graphql_query/schema/
introspection.rs

1#[cfg(feature = "json")]
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug)]
5#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
6pub struct IntrospectionQuery<'a> {
7    #[cfg_attr(feature = "json", serde(rename = "__schema", borrow))]
8    pub schema: IntrospectionSchema<'a>,
9}
10
11#[derive(Debug, Default)]
12#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
13#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
14pub struct IntrospectionSchema<'a> {
15    pub query_type: Option<IntrospectionNamedTypeRef<'a>>,
16    pub mutation_type: Option<IntrospectionNamedTypeRef<'a>>,
17    pub subscription_type: Option<IntrospectionNamedTypeRef<'a>>,
18    #[cfg_attr(feature = "json", serde(borrow))]
19    pub types: Vec<IntrospectionType<'a>>,
20    #[cfg_attr(feature = "json", serde(skip))]
21    pub directives: Option<Vec<IntrospectionDirective<'a>>>,
22}
23
24#[derive(Debug)]
25#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
26#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
27pub struct IntrospectionDeprecation<'a> {
28    pub is_deprecated: Option<bool>,
29    #[cfg_attr(feature = "json", serde(skip))]
30    pub deprecation_reason: Option<&'a str>,
31}
32
33#[derive(Debug)]
34#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
35#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
36pub struct IntrospectionObjectImplementation<'a> {
37    #[cfg_attr(feature = "json", serde(borrow))]
38    pub fields: Vec<IntrospectionField<'a>>,
39    #[cfg_attr(feature = "json", serde(borrow))]
40    pub interfaces: Option<Vec<IntrospectionNamedTypeRef<'a>>>,
41}
42
43#[derive(Debug)]
44#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
45#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
46pub struct IntrospectionPossibleTypes<'a> {
47    #[cfg_attr(feature = "json", serde(borrow))]
48    pub possible_types: Vec<IntrospectionNamedTypeRef<'a>>,
49}
50
51#[derive(Debug)]
52#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
53#[cfg_attr(
54    feature = "json",
55    serde(tag = "kind", rename_all = "SCREAMING_SNAKE_CASE")
56)]
57pub enum IntrospectionType<'a> {
58    #[cfg_attr(feature = "json", serde(borrow))]
59    Scalar(IntrospectionScalarType<'a>),
60    Object(IntrospectionObjectType<'a>),
61    Interface(IntrospectionInterfaceType<'a>),
62    Union(IntrospectionUnionType<'a>),
63    Enum(IntrospectionEnumType<'a>),
64    InputObject(IntrospectionInputObjectType<'a>),
65}
66
67impl<'a> IntrospectionType<'a> {
68    #[inline]
69    pub fn name(&self) -> &'a str {
70        match self {
71            IntrospectionType::Scalar(x) => x.name,
72            IntrospectionType::Object(x) => x.name,
73            IntrospectionType::Interface(x) => x.name,
74            IntrospectionType::Union(x) => x.name,
75            IntrospectionType::Enum(x) => x.name,
76            IntrospectionType::InputObject(x) => x.name,
77        }
78    }
79}
80
81#[derive(Debug, Clone)]
82#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
83#[cfg_attr(feature = "json", serde(tag = "kind"))]
84pub enum IntrospectionOutputTypeRef<'a> {
85    #[cfg_attr(feature = "json", serde(rename = "LIST"))]
86    List {
87        #[cfg_attr(feature = "json", serde(rename = "ofType"))]
88        of_type: Box<IntrospectionOutputTypeRef<'a>>,
89    },
90    #[cfg_attr(feature = "json", serde(rename = "NON_NULL"))]
91    NonNull {
92        #[cfg_attr(feature = "json", serde(rename = "ofType"))]
93        of_type: Box<IntrospectionOutputTypeRef<'a>>,
94    },
95    #[cfg_attr(feature = "json", serde(rename = "SCALAR"))]
96    ScalarType {
97        #[cfg_attr(feature = "json", serde(borrow))]
98        name: &'a str,
99    },
100    #[cfg_attr(feature = "json", serde(rename = "OBJECT"))]
101    ObjectType {
102        #[cfg_attr(feature = "json", serde(borrow))]
103        name: &'a str,
104    },
105    #[cfg_attr(feature = "json", serde(rename = "INTERFACE"))]
106    InterfaceType {
107        #[cfg_attr(feature = "json", serde(borrow))]
108        name: &'a str,
109    },
110    #[cfg_attr(feature = "json", serde(rename = "UNION"))]
111    UnionType {
112        #[cfg_attr(feature = "json", serde(borrow))]
113        name: &'a str,
114    },
115    #[cfg_attr(feature = "json", serde(rename = "ENUM"))]
116    EnumType {
117        #[cfg_attr(feature = "json", serde(borrow))]
118        name: &'a str,
119    },
120}
121
122#[derive(Debug)]
123#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
124#[cfg_attr(feature = "json", serde(tag = "kind"))]
125pub enum IntrospectionInputTypeRef<'a> {
126    #[cfg_attr(feature = "json", serde(rename = "LIST"))]
127    List {
128        #[cfg_attr(feature = "json", serde(rename = "ofType"))]
129        of_type: Box<IntrospectionInputTypeRef<'a>>,
130    },
131    #[cfg_attr(feature = "json", serde(rename = "NON_NULL"))]
132    NonNull {
133        #[cfg_attr(feature = "json", serde(rename = "ofType"))]
134        of_type: Box<IntrospectionInputTypeRef<'a>>,
135    },
136    #[cfg_attr(feature = "json", serde(rename = "SCALAR"))]
137    ScalarType {
138        #[cfg_attr(feature = "json", serde(borrow))]
139        name: &'a str,
140    },
141    #[cfg_attr(feature = "json", serde(rename = "ENUM"))]
142    EnumType {
143        #[cfg_attr(feature = "json", serde(borrow))]
144        name: &'a str,
145    },
146    #[cfg_attr(feature = "json", serde(rename = "INPUT_OBJECT"))]
147    InputObjectType {
148        #[cfg_attr(feature = "json", serde(borrow))]
149        name: &'a str,
150    },
151}
152
153#[derive(Debug)]
154#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
155#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
156pub struct IntrospectionNamedTypeRef<'a> {
157    #[cfg_attr(feature = "json", serde(skip))]
158    pub kind: Option<&'a str>,
159    #[cfg_attr(feature = "json", serde(borrow))]
160    pub name: &'a str,
161}
162
163#[derive(Debug)]
164#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
165#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
166pub struct IntrospectionScalarType<'a> {
167    #[cfg_attr(feature = "json", serde(borrow))]
168    pub name: &'a str,
169    #[cfg_attr(feature = "json", serde(skip))]
170    pub description: Option<&'a str>,
171    #[cfg_attr(feature = "json", serde(skip))]
172    pub specified_by_url: Option<&'a str>,
173}
174
175#[derive(Debug)]
176#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
177#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
178pub struct IntrospectionObjectType<'a> {
179    #[cfg_attr(feature = "json", serde(borrow))]
180    pub name: &'a str,
181    #[cfg_attr(feature = "json", serde(skip))]
182    pub description: Option<&'a str>,
183    #[cfg_attr(feature = "json", serde(flatten))]
184    pub implementation: IntrospectionObjectImplementation<'a>,
185}
186
187impl<'a> From<IntrospectionObjectType<'a>> for IntrospectionObjectImplementation<'a> {
188    #[inline]
189    fn from(obj: IntrospectionObjectType<'a>) -> Self {
190        obj.implementation
191    }
192}
193
194#[derive(Debug)]
195#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
196#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
197pub struct IntrospectionInterfaceType<'a> {
198    #[cfg_attr(feature = "json", serde(borrow))]
199    pub name: &'a str,
200    #[cfg_attr(feature = "json", serde(skip))]
201    pub description: Option<String>,
202    #[cfg_attr(feature = "json", serde(flatten))]
203    pub implementation: IntrospectionObjectImplementation<'a>,
204    #[cfg_attr(feature = "json", serde(flatten))]
205    pub possible_types: IntrospectionPossibleTypes<'a>,
206}
207
208impl<'a> From<IntrospectionInterfaceType<'a>> for IntrospectionObjectImplementation<'a> {
209    #[inline]
210    fn from(obj: IntrospectionInterfaceType<'a>) -> Self {
211        obj.implementation
212    }
213}
214
215impl<'a> From<IntrospectionInterfaceType<'a>> for IntrospectionPossibleTypes<'a> {
216    #[inline]
217    fn from(obj: IntrospectionInterfaceType<'a>) -> Self {
218        obj.possible_types
219    }
220}
221
222#[derive(Debug)]
223#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
224#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
225pub struct IntrospectionUnionType<'a> {
226    #[cfg_attr(feature = "json", serde(borrow))]
227    pub name: &'a str,
228    #[cfg_attr(feature = "json", serde(skip))]
229    pub description: Option<&'a str>,
230    #[cfg_attr(feature = "json", serde(flatten))]
231    pub possible_types: IntrospectionPossibleTypes<'a>,
232}
233
234impl<'a> From<IntrospectionUnionType<'a>> for IntrospectionPossibleTypes<'a> {
235    #[inline]
236    fn from(obj: IntrospectionUnionType<'a>) -> Self {
237        obj.possible_types
238    }
239}
240
241#[derive(Debug)]
242#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
243#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
244pub struct IntrospectionEnumType<'a> {
245    #[cfg_attr(feature = "json", serde(borrow))]
246    pub name: &'a str,
247    #[cfg_attr(feature = "json", serde(skip))]
248    pub description: Option<&'a str>,
249    pub enum_values: Vec<IntrospectionEnumValue<'a>>,
250}
251
252#[derive(Debug)]
253#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
254#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
255pub struct IntrospectionInputObjectType<'a> {
256    #[cfg_attr(feature = "json", serde(borrow))]
257    pub name: &'a str,
258    #[cfg_attr(feature = "json", serde(skip))]
259    pub description: Option<&'a str>,
260    pub input_fields: Vec<IntrospectionInputValue<'a>>,
261}
262
263#[derive(Debug)]
264#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
265#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
266pub struct IntrospectionField<'a> {
267    #[cfg_attr(feature = "json", serde(borrow))]
268    pub name: &'a str,
269    #[cfg_attr(feature = "json", serde(skip))]
270    pub description: Option<&'a str>,
271
272    pub args: Vec<IntrospectionInputValue<'a>>,
273
274    #[cfg_attr(feature = "json", serde(rename = "type"))]
275    pub of_type: IntrospectionOutputTypeRef<'a>,
276    #[cfg_attr(feature = "json", serde(flatten))]
277    pub deprecation: IntrospectionDeprecation<'a>,
278}
279
280#[derive(Debug)]
281#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
282#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
283pub struct IntrospectionInputValue<'a> {
284    #[cfg_attr(feature = "json", serde(borrow))]
285    pub name: &'a str,
286    #[cfg_attr(feature = "json", serde(skip))]
287    pub description: Option<&'a str>,
288    #[cfg_attr(feature = "json", serde(skip))]
289    pub default_value: Option<String>,
290
291    #[cfg_attr(feature = "json", serde(rename = "type"))]
292    pub of_type: IntrospectionInputTypeRef<'a>,
293
294    #[cfg_attr(feature = "json", serde(flatten))]
295    pub deprecation: IntrospectionDeprecation<'a>,
296}
297
298#[derive(Debug)]
299#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
300#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
301pub struct IntrospectionEnumValue<'a> {
302    #[cfg_attr(feature = "json", serde(borrow))]
303    pub name: &'a str,
304    #[cfg_attr(feature = "json", serde(skip))]
305    pub description: Option<&'a str>,
306    #[cfg_attr(feature = "json", serde(flatten))]
307    pub deprecation: IntrospectionDeprecation<'a>,
308}
309
310#[derive(Debug)]
311#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
312#[cfg_attr(feature = "json", serde(rename_all = "camelCase"))]
313pub struct IntrospectionDirective<'a> {
314    #[cfg_attr(feature = "json", serde(borrow))]
315    pub name: &'a str,
316    #[cfg_attr(feature = "json", serde(skip))]
317    pub description: Option<&'a str>,
318    #[cfg_attr(feature = "json", serde(default))]
319    pub is_repeatable: bool,
320    pub locations: Vec<IntrospectionDirectiveLocation>,
321    pub args: Vec<IntrospectionInputValue<'a>>,
322}
323
324#[derive(Debug)]
325#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
326#[cfg_attr(feature = "json", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
327pub enum IntrospectionDirectiveLocation {
328    Query,
329    Mutation,
330    Subscription,
331    Field,
332    FragmentDefinition,
333    FragmentSpread,
334    InlineFragment,
335    VariableDefinition,
336    Schema,
337    Scalar,
338    Object,
339    FieldDefinition,
340    ArgumentDefinition,
341    Interface,
342    Union,
343    Enum,
344    EnumValue,
345    InputObject,
346    InputFieldDefinition,
347}