Releases: apollographql/apollo-rs
[email protected]
[email protected]
0.3.1 - 2022-11-04
Features
-
streaming lexer - Geal + goto-bus-stop, pull/115
To help improve performance and memory usage in the lexer, we are now
streaming all incoming tokens in the lexer implementation. -
extend
ast::*Value
node conversions - SimonSapin, pull/344The following node types implement conversion to standard types, extracting
their value:StringValue
→String
IntValue
→i32
FloatValue
→f64
BoolValue
→bool
These conversions are now also available:
- Through the
From
trait, not just theInto
trait - With borrowed nodes, not just owned
Example:
let node: &apollo_parser::ast::StringValue = /* something */; let value: String = node.clone().into(); // before let value = String::from(node); // now also possible
Documentation
[email protected]
[email protected]
0.3.0 - 2022-11-02
Breaking
-
compiler.parse is renamed to compiler.ast - lrlna, pull/290
compiler.ast()
returns theSyntaxTree
produced by the parser and is much
clearer method thancompiler.parse()
. -
selection.ty(db) now expects a
db
parameter - 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!Send
value that is no longer possible with
theParallelDatabase
implementation.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
,Person
is a suptype ofSearchResult
. In an InterfaceDefinition such
astype Business implements NamedEntity & ValuedEntity { # fields }
,
Business
is 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
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
andValidationStorage
. -
thread-safe compiler: introduce snapshots - lrlna, pull/295 + pull/332
Implements
ParallelDatabase
forRootDatabase
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_group
s 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_group
s 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-compiler
can now compile to a Wasm target withcargo check --target wasm32-unknown-unknown
.
[email protected]
0.3.0 - 2022-10-31 💀
BREAKING
-
remove the impl Display for generated nodes - goto-bus-stop, pull/330
The
Display
impls for generated nodes returned the source text for that
node. That's not a super common operation but it was very easy to access. It's
also a very different operation from eg.let content: String = node.string_value().into()
which returns the content of a string:
node.string_value().to_string()
returned the string as it was written in the
source code, quotes and escapes and all.Now
.to_string()
is replaced by a.source_string()
method. It allocates a
new String (just like.to_string()
did). A syntax node can represent
multiple slices (I think to support different structures like Ropes as
input?), so slicing the original source isn't actually possible.
Fixes
-
handle unexpected tokens in top-level document parsing - JrSchild, pull/324
Unexpected tokens directly inside a document would break the loop in the
parser, for example:@ { name }}
This resulted in the rest of the parsing to be skipped. An error is created
here instead.
Maintenance
-
reduce token copying - goto-bus-stop, pull/323
- Reduce token copying
Since the original lexer results are not needed anymore after this step,
we can take ownership of the tokens and errors vectors and reverse them
in-place without making a copy. Big schemas can have 100K+ tokens so
it's actually quite a lot of work to copy them.- Reduce double-clones of tokens in the parser
Some of these clones were not necessary. In particular the
.expect
method cloned the token unconditionally (including the string inside)
and then cloned the string again immediately afterwards. This removes
the first clone by reordering thecurrent.index()
call to satisfy the
borrow checker.The
.data().to_string()
clone is only used in the error case, but
avoiding that will require more work.
[email protected]
0.3.3 - 2022-10-31 👻
Features
-
provide TryFrom for encoder types - goto-bus-stop pull/329
ProvidesTryFrom
impls for the apollo-encoder AST types.The conversion effectively assumes that the apollo-parser AST is valid and
complete. Otherwise you get an Err, but not a very useful one, because the
TryFrom impl doesn't know anything about its parent (so we can't show source
code where the error originated for example).
[email protected]
0.2.12 - 2022-09-30
Fixes
-
unterminated string values with line terminators and unicode - lrlna, pull/320 fixes issue/318
We were missing adding a line terminator character to the errors created by the lexer in case of a unterminated string. This showed up incidentally while dealing with unicode and the fact that it's of a different byte length than most other characters.
[email protected]
[email protected]
0.3.2 - 2022-08-19
Fixes
-
trim double quotes in multilingual description encodings - lrlna
Mutilingual descriptions failed to be encoded when containing block string
characters. The encoder now works with block string multilingual descriptions
such as:""" котя любить дрімати в "кутку" з рослинами """