Skip to content

apollo-smith@0.1.1

Choose a tag to compare

@lrlna lrlna released this 01 Apr 10:41
· 773 commits to main since this release
3b7ccac

0.1.1 - 2022-04-01

Features

  • Add parser-impl feature flag - bnjjj, pull/197
    parser-impl feature in apollo-smith is used to convert
    apollo-parser types to apollo-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