apollo-compiler@0.3.0
0.3.0 - 2022-11-02
Breaking
-
compiler.parse is renamed to compiler.ast - lrlna, pull/290
compiler.ast()returns theSyntaxTreeproduced by the parser and is much
clearer method thancompiler.parse(). -
selection.ty(db) now expects a
dbparameter - lrlna, pull/290As 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!Sendvalue that is no longer possible with
theParallelDatabaseimplementation.To access HIR definitions, use
db.db_definitions()anddb.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 asunion SearchResult = Photo | Person,Personis a suptype ofSearchResult. In an InterfaceDefinition such
astype Business implements NamedEntity & ValuedEntity { # fields },
Businessis a subtype ofNamedEntity. -
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
UniqueArgumentdiagnostics 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
ValidationDatabaseandValidationStorage. -
thread-safe compiler: introduce snapshots - lrlna, pull/295 + pull/332
Implements
ParallelDatabaseforRootDatabaseof 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_groupwe 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-->DocumentAll of these
query_groups make up theRootDatabase, 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-compilercan now compile to a Wasm target withcargo check --target wasm32-unknown-unknown.