pub struct Schema {
    pub sources: SourceMap,
    pub schema_definition: Node<SchemaDefinition>,
    pub directive_definitions: IndexMap<Name, Node<DirectiveDefinition>>,
    pub types: IndexMap<NamedType, ExtendedType>,
    /* private fields */
}
Expand description

High-level representation of a GraphQL schema

Fields§

§sources: SourceMap

Source files, if any, that were parsed to contribute to this schema.

The schema (including parsed definitions) may have been modified since parsing.

§schema_definition: Node<SchemaDefinition>

The schema definition and its extensions, defining root operations

§directive_definitions: IndexMap<Name, Node<DirectiveDefinition>>

Built-in and explicit directive definitions

§types: IndexMap<NamedType, ExtendedType>

Definitions and extensions of built-in scalars, introspection types, and explicit types

Implementations§

source§

impl Schema

source

pub fn new() -> Self

Returns an (almost) empty schema.

It starts with built-in directives, built-in scalars, and introspection types. It can then be filled programatically.

source

pub fn parse(source_text: impl Into<String>, path: impl AsRef<Path>) -> Self

Parse a single source file into a schema, with the default parser configuration.

Create a Parser to use different parser configuration. Use builder() to build a schema from multiple parsed files.

source

pub fn builder() -> SchemaBuilder

Returns a new builder for creating a Schema from AST documents, initialized with built-in directives, built-in scalars, and introspection types

use apollo_compiler::Schema;

let empty_schema = Schema::builder().build();
source

pub fn validate(&self) -> Result<Diagnostics, Diagnostics>

Returns Err if invalid, or Ok for potential warnings or advice

source

pub fn get_scalar(&self, name: &str) -> Option<&Node<ScalarType>>

Returns the type with the given name, if it is a scalar type

source

pub fn get_object(&self, name: &str) -> Option<&Node<ObjectType>>

Returns the type with the given name, if it is a object type

source

pub fn get_interface(&self, name: &str) -> Option<&Node<InterfaceType>>

Returns the type with the given name, if it is a interface type

source

pub fn get_union(&self, name: &str) -> Option<&Node<UnionType>>

Returns the type with the given name, if it is a union type

source

pub fn get_enum(&self, name: &str) -> Option<&Node<EnumType>>

Returns the type with the given name, if it is a enum type

source

pub fn get_input_object(&self, name: &str) -> Option<&Node<InputObjectType>>

Returns the type with the given name, if it is a input object type

source

pub fn root_operation( &self, operation_type: OperationType ) -> Option<&NamedType>

Returns the name of the object type for the root operation with the given operation kind

source

pub fn type_field( &self, type_name: &str, field_name: &str ) -> Result<&Component<FieldDefinition>, FieldLookupError<'_>>

Returns the definition of a type’s explicit field or meta-field.

source

pub fn is_subtype(&self, abstract_type: &str, maybe_subtype: &str) -> bool

Returns whether maybe_subtype is a subtype of abstract_type, which means either:

  • maybe_subtype implements the interface abstract_type
  • maybe_subtype is a member of the union type abstract_type
source

pub fn is_input_type(&self, ty: &Type) -> bool

Returns whether the type ty is defined as is an input type

https://spec.graphql.org/October2021/#sec-Input-and-Output-Types

source

pub fn is_output_type(&self, ty: &Type) -> bool

Returns whether the type ty is defined as is an output type

https://spec.graphql.org/October2021/#sec-Input-and-Output-Types

source

pub fn serialize(&self) -> Serialize<'_, Self>

Returns a builder that has chaining methods for setting serialization configuration, and implements the Display and ToString traits by writing GraphQL syntax.

Trait Implementations§

source§

impl Clone for Schema

source§

fn clone(&self) -> Schema

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Schema

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Schema

Serialize to GraphQL syntax with the default configuration

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Schema

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Schema

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> Fmt for T
where T: Display,

source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified foreground colour.
source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified background colour.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where 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> StdoutFmt for T
where T: Display,

source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>,

Give this value the specified foreground colour, when color is enabled for stdout.
source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>,

Give this value the specified background colour, when color is enabled for stdout.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.