Releases: apollographql/apollo-rs
[email protected]
0.1.1 - 2022-04-01
Features
-
Add
parser-impl
feature flag - bnjjj, pull/197
parser-impl
feature inapollo-smith
is used to convert
apollo-parser
types toapollo-smith
types. This is useful when you require
the test-case generator to generate documents based on a given schema.## Cargo.toml [dependencies] apollo-smith = { version = "0.1.1", features = ["parser-impl"] }
use std::fs; use apollo_parser::Parser; use apollo_smith::{Document, DocumentBuilder}; use libfuzzer_sys::arbitrary::{Result, Unstructured}; /// This generate an arbitrary valid GraphQL operation pub fn generate_valid_operation(input: &[u8]) { let parser = Parser::new(&fs::read_to_string("supergraph.graphql").expect("cannot read file")); let tree = parser.parse(); if !tree.errors().is_empty() { panic!("cannot parse the graphql file"); } let mut u = Unstructured::new(input); // Convert `apollo_parser::Document` into `apollo_smith::Document`. let apollo_smith_doc = Document::from(tree.document()); // Create a `DocumentBuilder` given an existing document to match a schema. let mut gql_doc = DocumentBuilder::with_document(&mut u, apollo_smith_doc)?; let operation_def = gql_doc.operation_definition()?.unwrap(); Ok(operation_def.into()) }
-
Introduces semantic validations to the test-case generation - bnjjj, pull/197
Semantic validations currently include:
- Directives used in the document must already be defined
- Directives must be unique in a given Directive Location
- Default values must be of correct type
- Input values must be of correct type
- All type extensions are applied to an existing type
- Field arguments in fragments and operation definitions must be defined on
original type and must be of correct type
[email protected]
0.2.5 - 2021-04-01
Important: 1 breaking change below, indicated by BREAKING
BREAKING
- GraphQL Int Values are cast to i32 - bnjjj, pull/197
AST's Int Values have anInto
implementation to their Rust type. They were
previously converted to i64, which is not compliant with the spec. Int Values
are now converted to i32.if let ast::Value::IntValue(val) = argument.value().expect("Cannot get argument value.") { let i: i32 = val.into(); }
Features
-
Adds a .text() method to ast::DirectiveLocation - bnjjj, pull/197
DirectiveLocation
can now additionally be accessed with a.text()
method.let schema = r#"directive @example on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT"#; let parser = Parser::new(schema); let ast = parser.parse(); assert!(ast.errors.is_empty()); let document = ast.document(); for definition in document.definitions() { if let ast::Definition::DirectiveDefinition(dir_def) = definition { let dir_locations: Vec<String> = dir_def .directive_locations() .unwrap() .directive_locations() .map(|loc| loc.text().unwrap().to_string()) .collect(); assert_eq!( dir_locations, ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"] ); return; } }
[email protected]
[email protected]
0.2.4 - 2021-03-07
Fixes
-
correctly parse Arguments Definition - bnjjj, pull/187 closes issue/186
apollo-parser
was creating ARGUMENTS instead of ARGUMENTS_DEFINITION nodes
when parsing Arguments Definitions. This change fixes the incorrect parsing
and allows to iterate over arguments definitions returned by the AST. -
Add STRING_VALUE node to DESCRIPTION - bnjjj, pull/188 closes issue/185
DESCRIPTION nodes are composed of STRING_VALUE nodes. The description string
was previously simply added to the DESCRIPTION node which was not spec
compliant. -
Schema Definition has a description - bnjjj, pull/188 closes issue/185
apollo-parser
was parsing descriptions in Schema Definitions, but the
graphql ungrammar did not account for a description node. This updates the
ungrammar, and provides an accessor method to Schema Definition's description. -
Add
repeatable
keyword to GraphQL ungrammar - bnjjj, pull/189repeatable
keyword was not able to be accessed programmatically from the
parsed AST for Directive Definitions, this is now fixed.
[email protected]
0.2.2 - 2022-02-28
BREAKING
-
Rename
InputValueDef
intoInputValueDefinition
for consistency - bnjjj, [pull/182] -
Rename
input_object_
method intoinput_object
onDocument
- bnjjj, [pull/182]
Fixes
-
Remove leading and ending
"
inBlockStringCharacter
encoding only when it starts and end with a"
- bnjjj, [pull/182]
This ensures that a StringValue of type BlockStringCharacter, like the one in
the test example below, does not getting encoded with an additional"
ending
up with""""
leading set of characters.let desc = StringValue::Reason { source: Some("One of my cat is called:\r \"Mozart\"".to_string()), }; assert_eq!( desc.to_string(), String::from("\n \"\"\"\n One of my cat is called:\r \"Mozart\"\n \"\"\"\n ") ); );
[email protected]
Introducing apollo-smith
!
The goal of apollo-smith is to generate valid GraphQL documents by sampling from all available possibilities of GraphQL grammar.
We've written apollo-smith to use in fuzzing, but you may wish to use it for anything that requires GraphQL document generation.
apollo-smith is inspired by bytecodealliance's wasm-smith crate, and the article written by Nick Fitzgerald on writing test case generators in Rust.
This is still a work in progress, for outstanding issues, checkout out the apollo-smith label in our issue tracker.
[email protected]
0.2.3 - 2021-02-17
Features
-
expose Lexer as a pub struct - bnjjj, pull/168
The
Lexer
inapollo-parser
is now a publicly available interface.use apollo_parser::Lexer; let query = " { animal ...snackSelection ... on Pet { playmates { count } } } "; let lexer = Lexer::new(query); assert_eq!(lexer.errors().len(), 0); let tokens = lexer.tokens();
Fixes
-
add a getter for Directives in Variable Definitions - lrlna, pull/172
While the parser was correctly parsing and accounting for directives in a
variable definition, the getter for Directives in VariableDefinition type in the
AST was missing. This commit makes an addition to the graphql ungrammar, and by
extension the generated AST nodes API.
[email protected]
0.2.1 - 2021-02-17
Fixes
-
Remove leading and ending
"
inBlockStringCharacter
encoding - bnjjj, pull/168
This ensures that a StringValue of type BlockStringCharacter, like the one in
the test example below, does not getting encoded with an additional"
ending
up with""""
leading set of characters.let desc = StringValue::Top { source: Some( "\"Favourite nap spots include: plant corner, pile of clothes.\"" .to_string(), ), }; assert_eq!( desc.to_string(), r#"""" Favourite nap spots include: plant corner, pile of clothes. """ "# );