Skip to content

apollo-compiler@0.3.0

Choose a tag to compare

@lrlna lrlna released this 02 Nov 14:32
· 679 commits to main since this release
e72853c

0.3.0 - 2022-11-02

Breaking

  • compiler.parse is renamed to compiler.ast - lrlna, pull/290

    compiler.ast() returns the SyntaxTree produced by the parser and is much
    clearer method than compiler.parse().

  • selection.ty(db) now expects a db parameter - lrlna, pull/290

    As byproduct of separating compiler's query_groups into individual components.
    Selection's type can now be accessed like so:

    let ctx = ApolloCompiler::new(input);
    let top_product_fields: Vec<String> = top_products
      .iter()
      .filter_map(|field| Some(field.ty(&ctx.db)?.name()))
      .collect();
  • removes db.definitions() API - lrlna, pull/295

    db.definitions() returned a !Send value that is no longer possible with
    the ParallelDatabase implementation.

    To access HIR definitions, use db.db_definitions() and db.type_system_definitions.

Features

  • add subtype_map and is_subtype queries - lrlna/SimonSapin, pull/333

    This allows users to check whether a particular type is a subtype of another
    type. For example, in a UnionDefinition such as union SearchResult = Photo | Person, Person is a suptype of SearchResult. In an InterfaceDefinition such
    as type Business implements NamedEntity & ValuedEntity { # fields },
    Business is a subtype of NamedEntity.

  • pub compiler storage - allow database composition - lrlna, pull/328

    This allows for internal query_groups to be exported, and allows users to
    compose various databases from compiler's existing dbs and their queries.

    This is how you'd create a database with storage from apollo-compiler:

    use apollo_compiler::{database::{AstStorage, DocumentStorage}};
    
    #[salsa::database(AstStorage, DoumentStorage)]
    pub struct AnotherDatabase {
        pub storage: salsa::Storage<AnotherDatabase>,
    }

    You can also see a more detailed linting example in examples dir.

  • validate argument name uniqueness - goto-bus-stop, pull/317

    It's an error to declare or provide multiple arguments by the same name, eg:

    type Query {
      things(offset: Int!, offset: Int!): [Thing]
      # ERR: duplicate argument definition: offset
    }
    query GetThings {
      things(offset: 10, offset: 20) { id }
      # ERR: duplicate argument values: offset
    }

    This adds UniqueArgument diagnostics and checks for argument duplications in:
    field definitions, fields, directives, interfaces and directive definitions.

  • getter for directives in HIR FragmentSpread - allancalix, pull/315

    Allow accessing directives in a given FragmentSpread node in a high-level
    intermediate representation of the compiler.

  • create validation database - lrlna, pull/303

    All validation now happens in its own database, which can be accessed with
    ValidationDatabase and ValidationStorage.

  • thread-safe compiler: introduce snapshots - lrlna, pull/295 + pull/332

    Implements ParallelDatabase for RootDatabase of the compiler. This allows
    us to create snapshots that can allow users to query the database from
    multiple threads. For example:

    let input = r#"
    type Query {
      website: URL,
      amount: Int
    }
    
    scalar URL @specifiedBy(url: "https://tools.ietf.org/html/rfc3986")
    "#;
    
    let ctx = ApolloCompiler::new(input);
    let diagnostics = ctx.validate();
    for diagnostic in &diagnostics {
        println!("{}", diagnostic);
    }
    
    assert!(diagnostics.is_empty());
    
    let snapshot = ctx.snapshot();
    let snapshot2 = ctx.snapshot();
    
    let thread1 = std::thread::spawn(move || snapshot.find_object_type_by_name("Query".into()));
    let thread2 = std::thread::spawn(move || snapshot2.scalars());
    
    thread1.join().expect("object_type_by_name panicked");
    thread2.join().expect("scalars failed");
  • add description getters to compiler's HIR nodes - aschaeffer, pull/289

    Expose getters for descriptions that can be accessed for any definitions that
    support them. For example:

    let input = r#"
    "Books in a given libary"
    type Book {
      id: ID!
    }
    "#;
    
    let ctx = ApolloCompiler::new(input);
    
    let desc = ctx.db.find_object_type_by_name("Book".to_string()).unwrap().description();

Fixes

  • update parser version - goto-bus-stop, pull/331

  • unused variables return an error diagnostic - lrlna, pull/314

    We were previously returning a warning for any unused variables, it is now
    reported as an error.

Maintenance

  • split up db into several components - lrlna, pull/290

    We are splitting up the single query_group we had in our db into several
    query_groups that currently just build upon each other, and eventually could
    support more complex relationships between one another. The current structure:

    Inputs --> DocumentParser --> Definitions --> Document

    All of these query_groups make up the RootDatabase, i.e. salsa::database.

    This also allows external users to build out their own databases with
    compiler's query groups.

  • support wasm compiler target - allancalix, pull/287, issue/288

    apollo-compiler can now compile to a Wasm target with cargo check --target wasm32-unknown-unknown.