Features
- A (comparatively) low-level AST for GraphQL grammar,
and high-level representation of
Schema
andExecutableDocument
. - All three can be parsed (using
apollo-parser
internally), created or modified programatically, and serialized. - Validation of schemas and executable documents, as defined in the GraphQL specification.
Getting started
Add the dependency to start using apollo-compiler
:
Or add this to your Cargo.toml
for a manual installation:
# Just an example, change to the necessary package version.
[]
= "1.0.0-beta.2"
Rust versions
apollo-compiler
is tested on the latest stable version of Rust.
Older version may or may not be compatible.
Usage
You can get started with apollo-compiler
:
use Schema;
let input = r#"
interface Pet {
name: String
}
type Dog implements Pet {
name: String
nickname: String
barkVolume: Int
}
type Cat implements Pet {
name: String
nickname: String
meowVolume: Int
}
union CatOrDog = Cat | Dog
type Human {
name: String
pets: [Pet]
}
type Query {
human: Human
}
"#;
let schema = parse;
/// In case of validation errors, the panic message will be nicely formatted
/// to point at relevant parts of the source file(s)
schema.validate.unwrap;
Examples
Accessing fragment definition field types
use ;
Get a directive defined on a field used in a query operation definition.
use ;
Printing diagnostics for a faulty GraphQL document
let input = r#"
query {
cat {
name
}
}
query getPet {
cat {
owner {
name
}
}
}
query getPet {
cat {
treat
}
}
subscription sub {
newMessage {
body
sender
}
disallowedSecondRootField
}
type Query {
cat: Pet
}
type Subscription {
newMessage: Result
}
interface Pet {
name: String
}
type Dog implements Pet {
name: String
nickname: String
barkVolume: Int
}
type Cat implements Pet {
name: String
nickname: String
meowVolume: Int
}
union CatOrDog = Cat | Dog
"#;
let = parse_mixed;
if let Err = schema.validate
if let Err = executable.validate
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.