pub struct Schema {
pub sources: SourceMap,
pub schema_definition: Node<SchemaDefinition>,
pub directive_definitions: IndexMap<Name, Node<DirectiveDefinition>>,
pub types: IndexMap<NamedType, ExtendedType>,
}
Expand description
High-level representation of a GraphQL type system document a.k.a. 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 all types relevant to a schema:
-
Explict types in parsed input files or added programatically.
-
Schema-introspection types such as
__Schema
,__Field
, etc. -
When a
Schema
is initially created or parsed, all Built-in scalars. After validation, the Rusttypes
map in aValid<Schema>
only contains built-in scalar definitions for scalars that are used in the schema. We reflect in this Rust API the behavior of__Schema.types
in GraphQL introspection.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn new() -> Self
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.
Sourcepub fn parse(
source_text: impl Into<String>,
path: impl AsRef<Path>,
) -> Result<Self, WithErrors<Self>>
pub fn parse( source_text: impl Into<String>, path: impl AsRef<Path>, ) -> Result<Self, WithErrors<Self>>
Sourcepub fn parse_and_validate(
source_text: impl Into<String>,
path: impl AsRef<Path>,
) -> Result<Valid<Self>, WithErrors<Self>>
pub fn parse_and_validate( source_text: impl Into<String>, path: impl AsRef<Path>, ) -> Result<Valid<Self>, WithErrors<Self>>
Sourcepub fn builder() -> SchemaBuilder
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();
pub fn validate(self) -> Result<Valid<Self>, WithErrors<Self>>
Sourcepub fn get_scalar(&self, name: &str) -> Option<&Node<ScalarType>>
pub fn get_scalar(&self, name: &str) -> Option<&Node<ScalarType>>
Returns the type with the given name, if it is a scalar type
Sourcepub fn get_object(&self, name: &str) -> Option<&Node<ObjectType>>
pub fn get_object(&self, name: &str) -> Option<&Node<ObjectType>>
Returns the type with the given name, if it is a object type
Sourcepub fn get_interface(&self, name: &str) -> Option<&Node<InterfaceType>>
pub fn get_interface(&self, name: &str) -> Option<&Node<InterfaceType>>
Returns the type with the given name, if it is a interface type
Sourcepub fn get_union(&self, name: &str) -> Option<&Node<UnionType>>
pub fn get_union(&self, name: &str) -> Option<&Node<UnionType>>
Returns the type with the given name, if it is a union type
Sourcepub fn get_enum(&self, name: &str) -> Option<&Node<EnumType>>
pub fn get_enum(&self, name: &str) -> Option<&Node<EnumType>>
Returns the type with the given name, if it is a enum type
Sourcepub fn get_input_object(&self, name: &str) -> Option<&Node<InputObjectType>>
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
Sourcepub fn root_operation(
&self,
operation_type: OperationType,
) -> Option<&NamedType>
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
Sourcepub fn type_field(
&self,
type_name: &str,
field_name: &str,
) -> Result<&Component<FieldDefinition>, FieldLookupError<'_>>
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.
Sourcepub fn implementers_map(&self) -> HashMap<Name, Implementers>
pub fn implementers_map(&self) -> HashMap<Name, Implementers>
Returns a map of interface names to names of types that implement that interface
Schema
only stores the inverse relationship
(in ObjectType::implements_interfaces
and InterfaceType::implements_interfaces
),
so iterating the implementers of an interface requires a linear scan
of all types in the schema.
If that is repeated for multiple interfaces,
gathering them all at once amorticizes that cost.
Sourcepub fn is_subtype(&self, abstract_type: &str, maybe_subtype: &str) -> bool
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 interfaceabstract_type
maybe_subtype
is a member of the union typeabstract_type
Sourcepub fn is_input_type(&self, ty: &Type) -> bool
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
Sourcepub fn is_output_type(&self, ty: &Type) -> bool
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
Trait Implementations§
impl Eq for Schema
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe for Schema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);