Crate apollo_encoder[−][src]
Expand description
For more information on GraphQL Schema Types, please refer to official documentation.
Getting started
Add this to your Cargo.toml to start using apollo-encoder:
[dependencies]
apollo-encoder = "0.1.0"Or using cargo-edit:
cargo add apollo-encoderExample
use apollo_encoder::{Schema, Field, UnionDef, EnumValue, Directive, EnumDef, Type_};
use indoc::indoc;
let mut schema = Schema::new();
// Create a Directive Definition.
let mut directive = Directive::new("provideTreat".to_string());
directive.description(Some("Ensures cats get treats.".to_string()));
directive.location("OBJECT".to_string());
directive.location("FIELD_DEFINITION".to_string());
directive.location("INPUT_FIELD_DEFINITION".to_string());
schema.directive(directive);
// Create an Enum Definition
let mut enum_ty_1 = EnumValue::new("CatTree".to_string());
enum_ty_1.description(Some("Top bunk of a cat tree.".to_string()));
let enum_ty_2 = EnumValue::new("Bed".to_string());
let mut enum_ty_3 = EnumValue::new("CardboardBox".to_string());
enum_ty_3.deprecated(Some("Box was recycled.".to_string()));
let mut enum_def = EnumDef::new("NapSpots".to_string());
enum_def.description(Some("Favourite cat\nnap spots.".to_string()));
enum_def.value(enum_ty_1);
enum_def.value(enum_ty_2);
enum_def.value(enum_ty_3);
schema.enum_(enum_def);
// Union Definition
let mut union_def = UnionDef::new("Cat".to_string());
union_def.description(Some(
"A union of all cats represented within a household.".to_string(),
));
union_def.member("NORI".to_string());
union_def.member("CHASHU".to_string());
schema.union(union_def);
assert_eq!(
schema.finish(),
indoc! { r#"
"Ensures cats get treats."
directive @provideTreat on OBJECT | FIELD_DEFINITION | INPUT_FIELD_DEFINITION
"""
Favourite cat
nap spots.
"""
enum NapSpots {
"Top bunk of a cat tree."
CatTree
Bed
CardboardBox @deprecated(reason: "Box was recycled.")
}
"A union of all cats represented within a household."
union Cat = NORI | CHASHU
"# }
);License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Structs
The __Directive type represents a Directive that a service supports.
Enums are special scalars that can only have a defined set of values.
The __EnumValue type represents one of possible values of an enum.
The __Field type represents each field in an Object or Interface type.
Input Field in a given Input Object. A GraphQL Input Object defines a set of input fields; the input fields are either scalars, enums, or other input objects. Input fields are similar to Fields, but can have a default value.
Input objects are composite types used as inputs into queries defined as a list of named input values..
The __InputValue type represents field and directive arguments.
InterfaceDefs are an abstract type where there are common fields declared.
Object types represent concrete instantiations of sets of fields.
Represents scalar types such as Int, String, and Boolean. Scalars cannot have fields.
GraphQLSchema represented in Schema Definition Language.
A GraphQL service’s collective type system capabilities are referred to as that service’s “schema”.
UnionDefs are an abstract type where no common fields are declared.
Enums
Convenience enum to create a Description. Can be a Top level, a Field
level or an Input level. The variants are distinguished by the way they
get displayed, e.g. number of leading spaces.
Convenience Type_ implementation used when creating a Field.
Can be a NamedType, a NonNull or a List.