apollo-compiler@0.9.0
lrlna
released this
12 May 15:27
·
434 commits
to main
since this release
0.9.0 - 2023-05-12
This release completes GraphQL validation specification, making the compiler spec-compliant.
You can validate the entire corpus of the compiler, or run individual compiler validation rules. The example below runs the whole corpus, as well specifically runs compiler.db.validate_executable(file_id)
for each of the two defined operations.
let schema = r#"
type Query {
cat: Cat
}
type Cat{
name: String!
nickname: String
purrVolume: Int
doesKnowCommand(catCommand: CatCommand!): Boolean!
}
enum CatCommand {
HOP
}
"#;
let cat_name_op = r#"
query getCatName {
cat {
name
}
}
"#;
let cat_command_op = r#"
query getCatName {
cat {
doesNotKnowCommand
}
}
"#;
let mut compiler = ApolloCompiler::new();
compiler.add_type_system(schema, "schema.graphl");
let cat_name_file = compiler.add_executable(cat_name_op, "cat_name_op.graphql");
let cat_command_file = compiler.add_executable(cat_command_op, "cat_command_op.graphql");
// validate both the operation and the type system
let all_diagnostics = compiler.validate();
assert_eq!(all_diagnostics.len(), 1);
// validate just the executables individual
let cat_name_op_diagnotics = compiler.db.validate_executable(cat_name_file);
assert!(cat_name_op_diagnotics.is_empty());
let cat_command_op_diagnotics = compiler.db.validate_executable(cat_command_file);
// This one has an error, where a field queries is not defined.
assert_eq!(cat_command_op_diagnotics.len(), 1);
for diag in cat_command_op_diagnotics {
println!("{}", diag);
}
BREAKING
-
remove
impl Default
for ApolloCompiler, by [dariuszkuc] in pull/542 -
align HIR extension getters to those of their type definition, by lrlna in pull/540
The following methods were changed:
InputObjectTypeExtension.fields_definition()
->InputObjectTypeDefinition.fields()
ObjectTypeExtension.fields_definition()
->ObjectTypeExtension.fields()
InterfaceTypeExtension.fields_definition()
->InterfaceTypeExtension.fields()
EnumTypeExtension.enum_values_definition()
->EnumTypeExtension.values()
UnionTypeExtension.union_members()
->UnionTypeExtension.members()
Features
- validate values are of correct type, by lrlna in pull/550
- support the built-in
@deprecated
directive on arguments and input values, by goto-bus-stop in pull/518 - validate that variable usage is allowed, by lrlna in pull/537
- validate executable documents do not contain type definitions, by goto-bus-stop in pull/535
- validate union extensions, by goto-bus-stop in pull/534
- validate input object extensions, by goto-bus-stop in pull/533
- validate interface extensions, by goto-bus-stop in pull/532
- validate enum extensions, by goto-bus-stop in pull/528
- validate object type extensions, by goto-bus-stop in pull/524
- validate fragment spread is possible, by goto-bus-stop in pull/511
Fixes
- fix recursion cycle in
is_introspection
HIR getter, by allancalix and goto-bus-stop in pull/544 and pull/552