Struct apollo_compiler::ApolloCompiler
source · pub struct ApolloCompiler {
pub db: RootDatabase,
}
Fields§
§db: RootDatabase
Implementations§
source§impl ApolloCompiler
impl ApolloCompiler
Apollo compiler creates a context around your GraphQL. It creates references between various GraphQL types in scope.
Example
use apollo_compiler::ApolloCompiler;
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 mut compiler = ApolloCompiler::new();
compiler.add_type_system(input, "schema.graphql");
let diagnostics = compiler.validate();
for diagnostic in &diagnostics {
// this will pretty-print diagnostics using the miette crate.
println!("{}", diagnostic);
}
assert!(diagnostics.is_empty());
sourcepub fn recursion_limit(self, limit: usize) -> Self
pub fn recursion_limit(self, limit: usize) -> Self
Configure the recursion limit to use during parsing. Recursion limit must be set prior to adding sources to the compiler.
sourcepub fn token_limit(self, limit: usize) -> Self
pub fn token_limit(self, limit: usize) -> Self
Configure the token limit to use during parsing. Token limit must be set prior to adding sources to the compiler.
sourcepub fn set_type_system_hir(&mut self, schema: Arc<TypeSystem>)
pub fn set_type_system_hir(&mut self, schema: Arc<TypeSystem>)
Add or update a pre-computed input for type system definitions
sourcepub fn add_document(&mut self, input: &str, path: impl AsRef<Path>) -> FileId
pub fn add_document(&mut self, input: &str, path: impl AsRef<Path>) -> FileId
Add a document with executable and type system definitions and extensions to the compiler.
The path
argument is used to display diagnostics. If your GraphQL document
doesn’t come from a file, you can make up a name or provide the empty string.
It does not need to be unique.
Returns a FileId
that you can use to update the source text of this document.
sourcepub fn add_type_system(&mut self, input: &str, path: impl AsRef<Path>) -> FileId
pub fn add_type_system(&mut self, input: &str, path: impl AsRef<Path>) -> FileId
Add a document with type system definitions and extensions only to the compiler.
The path
argument is used to display diagnostics. If your GraphQL document
doesn’t come from a file, you can make up a name or provide the empty string.
It does not need to be unique.
Returns a FileId
that you can use to update the source text of this document.
sourcepub fn add_executable(&mut self, input: &str, path: impl AsRef<Path>) -> FileId
pub fn add_executable(&mut self, input: &str, path: impl AsRef<Path>) -> FileId
Add a an executable document to the compiler.
The path
argument is used to display diagnostics. If your GraphQL document
doesn’t come from a file, you can make up a name or provide the empty string.
It does not need to be unique.
Returns a FileId
that you can use to update the source text of this document.
sourcepub fn update_document(&mut self, file_id: FileId, input: &str)
pub fn update_document(&mut self, file_id: FileId, input: &str)
Update an existing GraphQL document with new source text. Queries that depend on this document will be recomputed.
sourcepub fn update_type_system(&mut self, file_id: FileId, input: &str)
pub fn update_type_system(&mut self, file_id: FileId, input: &str)
Update an existing GraphQL document with new source text. Queries that depend on this document will be recomputed.
sourcepub fn update_executable(&mut self, file_id: FileId, input: &str)
pub fn update_executable(&mut self, file_id: FileId, input: &str)
Update an existing GraphQL document with new source text. Queries that depend on this document will be recomputed.
sourcepub fn validate(&self) -> Vec<ApolloDiagnostic>
pub fn validate(&self) -> Vec<ApolloDiagnostic>
Validate your GraphQL input. Returns Diagnostics that you can pretty-print.
Example
use apollo_compiler::ApolloCompiler;
let input = r#"
type Query {
website: URL,
amount: Int
}
"#;
let mut compiler = ApolloCompiler::new();
compiler.add_document(input, "document.graphql");
let diagnostics = compiler.validate();
for diagnostic in &diagnostics {
println!("{}", diagnostic);
}
assert_eq!(diagnostics.len(), 1);