async_graphql_parser/types/
service.rs

1//! Service-related GraphQL types.
2
3use super::*;
4
5/// A GraphQL file or request string defining a GraphQL service.
6///
7/// [Reference](https://spec.graphql.org/October2021/#Document).
8#[derive(Debug, Clone)]
9pub struct ServiceDocument {
10    /// The definitions of this document.
11    pub definitions: Vec<TypeSystemDefinition>,
12}
13
14/// A definition concerning the type system of a GraphQL service.
15///
16/// [Reference](https://spec.graphql.org/October2021/#TypeSystemDefinition). This enum also covers
17/// [extensions](https://spec.graphql.org/October2021/#TypeSystemExtension).
18#[derive(Debug, Clone)]
19pub enum TypeSystemDefinition {
20    /// The definition of the schema of the service.
21    Schema(Positioned<SchemaDefinition>),
22    /// The definition of a type in the service.
23    Type(Positioned<TypeDefinition>),
24    /// The definition of a directive in the service.
25    Directive(Positioned<DirectiveDefinition>),
26}
27
28/// The definition of the schema in a GraphQL service.
29///
30/// [Reference](https://spec.graphql.org/October2021/#SchemaDefinition). This also covers
31/// [extensions](https://spec.graphql.org/October2021/#SchemaExtension).
32#[derive(Debug, Clone)]
33pub struct SchemaDefinition {
34    /// Whether the schema is an extension of another schema.
35    pub extend: bool,
36    /// The directives of the schema definition.
37    pub directives: Vec<Positioned<ConstDirective>>,
38    /// The query root. This is always `Some` when the schema is not extended.
39    pub query: Option<Positioned<Name>>,
40    /// The mutation root, if present.
41    pub mutation: Option<Positioned<Name>>,
42    /// The subscription root, if present.
43    pub subscription: Option<Positioned<Name>>,
44}
45
46/// The definition of a type in a GraphQL service.
47///
48/// [Reference](https://spec.graphql.org/October2021/#TypeDefinition). This also covers
49/// [extensions](https://spec.graphql.org/October2021/#TypeExtension).
50#[derive(Debug, Clone)]
51pub struct TypeDefinition {
52    /// Whether the type is an extension of another type.
53    pub extend: bool,
54    /// The description of the type, if present. This is never present on an
55    /// extension type.
56    pub description: Option<Positioned<String>>,
57    /// The name of the type.
58    pub name: Positioned<Name>,
59    /// The directives of type definition.
60    pub directives: Vec<Positioned<ConstDirective>>,
61    /// Which kind of type is being defined; scalar, object, enum, etc.
62    pub kind: TypeKind,
63}
64
65/// A kind of type; scalar, object, enum, etc.
66#[derive(Debug, Clone)]
67pub enum TypeKind {
68    /// A scalar type.
69    Scalar,
70    /// An object type.
71    Object(ObjectType),
72    /// An interface type.
73    Interface(InterfaceType),
74    /// A union type.
75    Union(UnionType),
76    /// An enum type.
77    Enum(EnumType),
78    /// An input object type.
79    InputObject(InputObjectType),
80}
81
82/// The definition of an object type.
83///
84/// [Reference](https://spec.graphql.org/October2021/#ObjectType).
85#[derive(Debug, Clone)]
86pub struct ObjectType {
87    /// The interfaces implemented by the object.
88    pub implements: Vec<Positioned<Name>>,
89    /// The fields of the object type.
90    pub fields: Vec<Positioned<FieldDefinition>>,
91}
92
93/// The definition of a field inside an object or interface.
94///
95/// [Reference](https://spec.graphql.org/October2021/#FieldDefinition).
96#[derive(Debug, Clone)]
97pub struct FieldDefinition {
98    /// The description of the field.
99    pub description: Option<Positioned<String>>,
100    /// The name of the field.
101    pub name: Positioned<Name>,
102    /// The arguments of the field.
103    pub arguments: Vec<Positioned<InputValueDefinition>>,
104    /// The type of the field.
105    pub ty: Positioned<Type>,
106    /// The directives of the field.
107    pub directives: Vec<Positioned<ConstDirective>>,
108}
109
110/// The definition of an interface type.
111///
112/// [Reference](https://spec.graphql.org/October2021/#InterfaceType).
113#[derive(Debug, Clone)]
114pub struct InterfaceType {
115    /// The interfaces implemented by the interface.
116    pub implements: Vec<Positioned<Name>>,
117    /// The fields of the interface type.
118    pub fields: Vec<Positioned<FieldDefinition>>,
119}
120
121/// The definition of a union type.
122///
123/// [Reference](https://spec.graphql.org/October2021/#UnionType).
124#[derive(Debug, Clone)]
125pub struct UnionType {
126    /// The member types of the union.
127    pub members: Vec<Positioned<Name>>,
128}
129
130/// The definition of an enum.
131///
132/// [Reference](https://spec.graphql.org/October2021/#EnumType).
133#[derive(Debug, Clone)]
134pub struct EnumType {
135    /// The possible values of the enum.
136    pub values: Vec<Positioned<EnumValueDefinition>>,
137}
138
139/// The definition of a value inside an enum.
140///
141/// [Reference](https://spec.graphql.org/October2021/#EnumValueDefinition).
142#[derive(Debug, Clone)]
143pub struct EnumValueDefinition {
144    /// The description of the argument.
145    pub description: Option<Positioned<String>>,
146    /// The value name.
147    pub value: Positioned<Name>,
148    /// The directives of the enum value.
149    pub directives: Vec<Positioned<ConstDirective>>,
150}
151
152/// The definition of an input object.
153///
154/// [Reference](https://spec.graphql.org/October2021/#InputObjectType).
155#[derive(Debug, Clone)]
156pub struct InputObjectType {
157    /// The fields of the input object.
158    pub fields: Vec<Positioned<InputValueDefinition>>,
159}
160
161/// The definition of an input value inside the arguments of a field.
162///
163/// [Reference](https://spec.graphql.org/October2021/#InputValueDefinition).
164#[derive(Debug, Clone)]
165pub struct InputValueDefinition {
166    /// The description of the argument.
167    pub description: Option<Positioned<String>>,
168    /// The name of the argument.
169    pub name: Positioned<Name>,
170    /// The type of the argument.
171    pub ty: Positioned<Type>,
172    /// The default value of the argument, if there is one.
173    pub default_value: Option<Positioned<ConstValue>>,
174    /// The directives of the input value.
175    pub directives: Vec<Positioned<ConstDirective>>,
176}
177
178/// The definition of a directive in a service.
179///
180/// [Reference](https://spec.graphql.org/October2021/#DirectiveDefinition).
181#[derive(Debug, Clone)]
182pub struct DirectiveDefinition {
183    /// The description of the directive.
184    pub description: Option<Positioned<String>>,
185    /// The name of the directive.
186    pub name: Positioned<Name>,
187    /// The arguments of the directive.
188    pub arguments: Vec<Positioned<InputValueDefinition>>,
189    /// Whether the directive can be repeated.
190    pub is_repeatable: bool,
191    /// The locations the directive applies to.
192    pub locations: Vec<Positioned<DirectiveLocation>>,
193}
194
195/// Where a directive can apply to.
196///
197/// [Reference](https://spec.graphql.org/October2021/#DirectiveLocation).
198#[derive(Debug, Clone, Copy, PartialEq, Eq)]
199pub enum DirectiveLocation {
200    /// A [query](enum.OperationType.html#variant.Query)
201    /// [operation](struct.OperationDefinition.html).
202    Query,
203    /// A [mutation](enum.OperationType.html#variant.Mutation)
204    /// [operation](struct.OperationDefinition.html).
205    Mutation,
206    /// A [subscription](enum.OperationType.html#variant.Subscription)
207    /// [operation](struct.OperationDefinition.html).
208    Subscription,
209    /// A [field](struct.Field.html).
210    Field,
211    /// A [fragment definition](struct.FragmentDefinition.html).
212    FragmentDefinition,
213    /// A [fragment spread](struct.FragmentSpread.html).
214    FragmentSpread,
215    /// An [inline fragment](struct.InlineFragment.html).
216    InlineFragment,
217    /// A [schema](struct.Schema.html).
218    Schema,
219    /// A [scalar](enum.TypeKind.html#variant.Scalar).
220    Scalar,
221    /// An [object](struct.ObjectType.html).
222    Object,
223    /// A [field definition](struct.FieldDefinition.html).
224    FieldDefinition,
225    /// An [input value definition](struct.InputFieldDefinition.html) as the
226    /// arguments of a field but not an input object.
227    ArgumentDefinition,
228    /// An [interface](struct.InterfaceType.html).
229    Interface,
230    /// A [union](struct.UnionType.html).
231    Union,
232    /// An [enum](struct.EnumType.html).
233    Enum,
234    /// A [value on an enum](struct.EnumValueDefinition.html).
235    EnumValue,
236    /// An [input object](struct.InputObjectType.html).
237    InputObject,
238    /// An [input value definition](struct.InputValueDefinition.html) on an
239    /// input object but not a field.
240    InputFieldDefinition,
241    /// An [variable definition](struct.VariableDefinition.html).
242    VariableDefinition,
243}