Skip to content

apollo-compiler@0.9.0

Compare
Choose a tag to compare
@lrlna 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

Fixes