Skip to content

Commit 01a14be

Browse files
committed
temp
1 parent f335c0d commit 01a14be

File tree

6 files changed

+61
-24
lines changed

6 files changed

+61
-24
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Apollo-Smith Next
2+
The next folder ****

crates/apollo-smith/src/next/mod.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,30 @@ pub enum Error {
3030
},
3131

3232
#[error("validation passed, but should have failed")]
33-
ExpectedValidationFail { doc: Document, mutation: String },
33+
SchemaExpectedValidationFail { doc: Document, mutation: String },
3434

3535
#[error("the serialized AST did not round trip to an identical AST")]
3636
SerializationInconsistency { original: Document, new: Document },
3737

3838
#[error("parse error")]
3939
Parse(WithErrors<Document>),
4040

41+
#[error("validation passed, but should have failed")]
42+
ExecutableExpectedValidationFail {
43+
schema: Valid<Schema>,
44+
doc: Document,
45+
mutation: String
46+
},
47+
4148
#[error("reparse error")]
42-
Reparse {
49+
SchemaReparse {
50+
doc: Document,
51+
errors: WithErrors<Document>,
52+
},
53+
54+
#[error("reparse error")]
55+
ExecutableReparse {
56+
schema: Valid<Schema>,
4357
doc: Document,
4458
errors: WithErrors<Document>,
4559
},
@@ -67,12 +81,13 @@ pub fn generate_schema_document(u: &mut Unstructured) -> Result<Document, Error>
6781
continue;
6882
}
6983

84+
7085
// Now let's validate that the schema says it's OK
7186
match (mutation.is_valid(), new_doc.to_schema_validate()) {
7287
(true, Ok(new_schema)) => {
7388
// Let's reparse the document to check that it can be parsed
7489
let reparsed = Document::parse(new_doc.to_string(), PathBuf::from("synthetic"))
75-
.map_err(|e| Error::Reparse {
90+
.map_err(|e| Error::SchemaReparse {
7691
doc: new_doc.clone(),
7792
errors: e,
7893
})?;
@@ -87,7 +102,6 @@ pub fn generate_schema_document(u: &mut Unstructured) -> Result<Document, Error>
87102

88103
// Let's try and create an executable document from the schema
89104
generate_executable_document(u, &new_schema)?;
90-
91105
schema = new_schema.into_inner();
92106
doc = new_doc;
93107
continue;
@@ -99,7 +113,7 @@ pub fn generate_schema_document(u: &mut Unstructured) -> Result<Document, Error>
99113
});
100114
}
101115
(false, Ok(_)) => {
102-
return Err(Error::ExpectedValidationFail {
116+
return Err(Error::SchemaExpectedValidationFail {
103117
doc: new_doc,
104118
mutation: mutation.type_name().to_string(),
105119
});
@@ -119,7 +133,7 @@ pub(crate) fn generate_executable_document(
119133
) -> Result<Document, Error> {
120134
let mut doc = Document::new();
121135
let mutations = mutations::executable_document_mutations();
122-
for _ in 0..1000 {
136+
for count in 0..1000 {
123137
if u.len() == 0 {
124138
// We ran out of data abort. This is not an error
125139
return Err(Error::Arbitrary(arbitrary::Error::NotEnoughData))?;
@@ -133,12 +147,12 @@ pub(crate) fn generate_executable_document(
133147
}
134148

135149
// Now let's validate that the schema says it's OK
136-
137150
match (mutation.is_valid(), new_doc.to_executable_validate(schema)) {
138151
(true, Ok(_)) => {
139152
// Let's reparse the document to check that it can be parsed
140153
let reparsed = Document::parse(new_doc.to_string(), PathBuf::from("synthetic"))
141-
.map_err(|e| Error::Reparse {
154+
.map_err(|e| Error::ExecutableReparse {
155+
schema: schema.clone(),
142156
doc: new_doc.clone(),
143157
errors: e,
144158
})?;
@@ -162,7 +176,7 @@ pub(crate) fn generate_executable_document(
162176
});
163177
}
164178
(false, Ok(_)) => {
165-
return Err(Error::ExpectedValidationFail {
179+
return Err(Error::SchemaExpectedValidationFail {
166180
doc: new_doc,
167181
mutation: mutation.type_name().to_string(),
168182
});

crates/apollo-smith/src/next/mutations/add_operation_definition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ impl Mutation for AddOperationDefinition {
1717
.push(Definition::OperationDefinition(Node::new(
1818
u.arbitrary_operation_definition(schema)?,
1919
)));
20-
Ok(false)
20+
Ok(true)
2121
}
2222
fn is_valid(&self) -> bool {
23-
false
23+
true
2424
}
2525
}

crates/apollo-smith/src/next/mutations/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(crate) fn schema_mutations() -> Vec<Box<dyn Mutation>> {
4848
Box::new(AddInputObjectTypeDefinition),
4949
Box::new(AddUnionTypeDefinition),
5050
Box::new(AddInterfaceTypeDefinition),
51-
Box::new(RemoveAllFields),
51+
//Box::new(RemoveAllFields),
5252
Box::new(RemoveRequiredField),
5353
]
5454
}

crates/apollo-smith/src/next/unstructured.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use crate::next::ast::directive_definition::DirectiveDefinitionIterExt;
1616
use crate::next::schema::extended_type::{ExtendedTypeExt, ExtendedTypeKind};
1717
use crate::next::schema::object_type::ObjectTypeExt;
1818
use crate::next::schema::schema::SchemaExt;
19+
use crate::next::schema::TypeHasFields;
20+
1921
pub struct Unstructured<'a> {
2022
u: arbitrary::Unstructured<'a>,
2123
counter: usize,
@@ -447,8 +449,10 @@ impl Unstructured<'_> {
447449
.sample_directives(self)?
448450
.into_iter()
449451
.with_location(DirectiveLocation::Field)
452+
// skip and include are not allowed on operations
453+
.filter(|d|d.name != "skip" && d.name != "include")
450454
.try_collect(self, schema)?,
451-
selection_set: self.arbitrary_vec(0, 5, |u| {
455+
selection_set: self.arbitrary_vec(1, 5, |u| {
452456
Ok(u.arbitrary_selection(schema, operation.deref())?)
453457
})?,
454458
})
@@ -484,7 +488,7 @@ impl Unstructured<'_> {
484488
.into_iter()
485489
.with_location(DirectiveLocation::InlineFragment)
486490
.try_collect(self, schema)?,
487-
selection_set: self.arbitrary_vec(0, 5, |u| Ok(u.arbitrary_selection(schema, ty)?))?,
491+
selection_set: self.arbitrary_vec(1, 5, |u| Ok(u.arbitrary_selection(schema, ty)?))?,
488492
})
489493
}
490494

@@ -502,22 +506,22 @@ impl Unstructured<'_> {
502506
fn arbitrary_selection(
503507
&mut self,
504508
schema: &Schema,
505-
ty: &dyn super::schema::TypeHasFields,
509+
ty: &dyn TypeHasFields,
506510
) -> Result<Selection> {
507511
match self.choose_index(3) {
508512
Ok(0) => {
509513
let field = ty.random_field(self)?;
510514
let field_ty = schema.types.get(field.ty.inner_named_type()).expect("type must exist");
511-
let selection_set = if field_ty.is_object() || field_ty.is_interface() {
512-
self.arbitrary_vec(0, 5, |u| {
515+
let selection_set = if field_ty.is_scalar() {
516+
vec![]
517+
} else {
518+
self.arbitrary_vec(1, 5, |u| {
513519
Ok(u.arbitrary_selection(schema, field_ty)?)
514520
})?
515-
} else {
516-
vec![]
517521
};
518522
Ok(Selection::Field(Node::new(Field {
519523
alias: self.arbitrary_optional(|u|Ok(u.unique_name()))?,
520-
name: self.unique_name(),
524+
name: field.name.clone(),
521525
arguments: self.arbitrary_vec(0, 5, |u| {
522526
Ok(Node::new(Argument {
523527
name: u.unique_name(),

fuzz/fuzz_targets/parser_next.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fuzz_target!(|data: &[u8]| {
2020
Error::Parse(doc) => {
2121
println!("{}\ndoc:\n{}\nerrors:\n{}", e, doc.to_string(), doc.errors);
2222
}
23-
Error::ExpectedValidationFail { doc, mutation } => {
23+
Error::SchemaExpectedValidationFail { doc, mutation } => {
2424
println!("{}\nmutation:\n{}\ndoc:\n{}", e, mutation, doc.to_string());
2525
}
2626
Error::SerializationInconsistency { original, new } => {
@@ -39,27 +39,44 @@ fuzz_target!(|data: &[u8]| {
3939
errors.errors
4040
);
4141
}
42-
Error::Reparse { doc, errors } => {
42+
Error::SchemaReparse { doc, errors } => {
4343
println!(
4444
"{}\ndoc:\n{}\nerrors:\n{}",
4545
e,
4646
doc.to_string(),
4747
errors.errors
4848
);
4949
}
50+
51+
Error::ExecutableReparse {
52+
schema,
53+
doc,
54+
errors,
55+
} => {
56+
println!(
57+
"{}\ndoc:\n{}\nschema:\n{}\nerrors:\n{}",
58+
e,
59+
doc.to_string(),
60+
schema.to_string(),
61+
errors.errors
62+
);
63+
}
5064
Error::ExecutableDocumentValidation {
5165
doc,
5266
schema,
5367
errors,
5468
} => {
5569
println!(
56-
"{}\nschena\n{}\ndoc:\n{}\nerrors:\n{}",
70+
"{}\ndoc\n{}\nschema:\n{}\nerrors:\n{}",
5771
e,
58-
schema.to_string(),
5972
doc.to_string(),
73+
schema.to_string(),
6074
errors.errors
6175
);
6276
}
77+
Error::ExecutableExpectedValidationFail { schema, doc, mutation } => {
78+
println!("{}\nmutation:\n{}\ndoc:\n{}\nschema\n{}", e, mutation, doc.to_string(), schema.to_string());
79+
}
6380
}
6481
panic!("error detected: {}", e);
6582
}

0 commit comments

Comments
 (0)