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 refernces 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 with_recursion_limit(limit: usize) -> Self
pub fn with_recursion_limit(limit: usize) -> Self
Create a new instance of Apollo Compiler, and configure the parser with the given recursion limit.
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);
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for ApolloCompiler
impl Send for ApolloCompiler
impl !Sync for ApolloCompiler
impl Unpin for ApolloCompiler
impl UnwindSafe for ApolloCompiler
Blanket Implementations§
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more