pub struct ApolloCompiler {
    pub db: RootDatabase,
}

Fields§

§db: RootDatabase

Implementations§

source§

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());
source

pub fn new() -> Self

Create a new instance of Apollo Compiler.

source

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.

source

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.

source

pub fn set_type_system_hir(&mut self, schema: Arc<TypeSystem>)

Add or update a pre-computed input for type system definitions

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn snapshot(&self) -> Snapshot

Get a snapshot of the current database.

source

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);

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.