graphql_introspection_query/
introspection_response.rs

1#![allow(non_camel_case_types)]
2
3use serde::{Deserialize, Deserializer, Serialize};
4
5#[derive(Clone, Debug)]
6pub enum __DirectiveLocation {
7    QUERY,
8    MUTATION,
9    SUBSCRIPTION,
10    FIELD,
11    FRAGMENT_DEFINITION,
12    FRAGMENT_SPREAD,
13    INLINE_FRAGMENT,
14    SCHEMA,
15    SCALAR,
16    OBJECT,
17    FIELD_DEFINITION,
18    ARGUMENT_DEFINITION,
19    INTERFACE,
20    UNION,
21    ENUM,
22    ENUM_VALUE,
23    INPUT_OBJECT,
24    INPUT_FIELD_DEFINITION,
25    Other(String),
26}
27
28impl Serialize for __DirectiveLocation {
29    fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
30        ser.serialize_str(match *self {
31            __DirectiveLocation::QUERY => "QUERY",
32            __DirectiveLocation::MUTATION => "MUTATION",
33            __DirectiveLocation::SUBSCRIPTION => "SUBSCRIPTION",
34            __DirectiveLocation::FIELD => "FIELD",
35            __DirectiveLocation::FRAGMENT_DEFINITION => "FRAGMENT_DEFINITION",
36            __DirectiveLocation::FRAGMENT_SPREAD => "FRAGMENT_SPREAD",
37            __DirectiveLocation::INLINE_FRAGMENT => "INLINE_FRAGMENT",
38            __DirectiveLocation::SCHEMA => "SCHEMA",
39            __DirectiveLocation::SCALAR => "SCALAR",
40            __DirectiveLocation::OBJECT => "OBJECT",
41            __DirectiveLocation::FIELD_DEFINITION => "FIELD_DEFINITION",
42            __DirectiveLocation::ARGUMENT_DEFINITION => "ARGUMENT_DEFINITION",
43            __DirectiveLocation::INTERFACE => "INTERFACE",
44            __DirectiveLocation::UNION => "UNION",
45            __DirectiveLocation::ENUM => "ENUM",
46            __DirectiveLocation::ENUM_VALUE => "ENUM_VALUE",
47            __DirectiveLocation::INPUT_OBJECT => "INPUT_OBJECT",
48            __DirectiveLocation::INPUT_FIELD_DEFINITION => "INPUT_FIELD_DEFINITION",
49            __DirectiveLocation::Other(ref s) => s.as_str(),
50        })
51    }
52}
53
54impl<'de> Deserialize<'de> for __DirectiveLocation {
55    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
56        let s = <&'de str>::deserialize(deserializer)?;
57        match s {
58            "QUERY" => Ok(__DirectiveLocation::QUERY),
59            "MUTATION" => Ok(__DirectiveLocation::MUTATION),
60            "SUBSCRIPTION" => Ok(__DirectiveLocation::SUBSCRIPTION),
61            "FIELD" => Ok(__DirectiveLocation::FIELD),
62            "FRAGMENT_DEFINITION" => Ok(__DirectiveLocation::FRAGMENT_DEFINITION),
63            "FRAGMENT_SPREAD" => Ok(__DirectiveLocation::FRAGMENT_SPREAD),
64            "INLINE_FRAGMENT" => Ok(__DirectiveLocation::INLINE_FRAGMENT),
65            "SCHEMA" => Ok(__DirectiveLocation::SCHEMA),
66            "SCALAR" => Ok(__DirectiveLocation::SCALAR),
67            "OBJECT" => Ok(__DirectiveLocation::OBJECT),
68            "FIELD_DEFINITION" => Ok(__DirectiveLocation::FIELD_DEFINITION),
69            "ARGUMENT_DEFINITION" => Ok(__DirectiveLocation::ARGUMENT_DEFINITION),
70            "INTERFACE" => Ok(__DirectiveLocation::INTERFACE),
71            "UNION" => Ok(__DirectiveLocation::UNION),
72            "ENUM" => Ok(__DirectiveLocation::ENUM),
73            "ENUM_VALUE" => Ok(__DirectiveLocation::ENUM_VALUE),
74            "INPUT_OBJECT" => Ok(__DirectiveLocation::INPUT_OBJECT),
75            "INPUT_FIELD_DEFINITION" => Ok(__DirectiveLocation::INPUT_FIELD_DEFINITION),
76            _ => Ok(__DirectiveLocation::Other(s.to_string())),
77        }
78    }
79}
80
81#[derive(Clone, Debug, PartialEq, Eq)]
82pub enum __TypeKind {
83    SCALAR,
84    OBJECT,
85    INTERFACE,
86    UNION,
87    ENUM,
88    INPUT_OBJECT,
89    LIST,
90    NON_NULL,
91    Other(String),
92}
93
94impl Serialize for __TypeKind {
95    fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
96        ser.serialize_str(match *self {
97            __TypeKind::SCALAR => "SCALAR",
98            __TypeKind::OBJECT => "OBJECT",
99            __TypeKind::INTERFACE => "INTERFACE",
100            __TypeKind::UNION => "UNION",
101            __TypeKind::ENUM => "ENUM",
102            __TypeKind::INPUT_OBJECT => "INPUT_OBJECT",
103            __TypeKind::LIST => "LIST",
104            __TypeKind::NON_NULL => "NON_NULL",
105            __TypeKind::Other(ref s) => s.as_str(),
106        })
107    }
108}
109
110impl<'de> Deserialize<'de> for __TypeKind {
111    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
112        let s = <&'de str>::deserialize(deserializer)?;
113        match s {
114            "SCALAR" => Ok(__TypeKind::SCALAR),
115            "OBJECT" => Ok(__TypeKind::OBJECT),
116            "INTERFACE" => Ok(__TypeKind::INTERFACE),
117            "UNION" => Ok(__TypeKind::UNION),
118            "ENUM" => Ok(__TypeKind::ENUM),
119            "INPUT_OBJECT" => Ok(__TypeKind::INPUT_OBJECT),
120            "LIST" => Ok(__TypeKind::LIST),
121            "NON_NULL" => Ok(__TypeKind::NON_NULL),
122            _ => Ok(__TypeKind::Other(s.to_string())),
123        }
124    }
125}
126
127#[derive(Clone, Debug, Deserialize)]
128#[serde(rename_all = "camelCase")]
129pub struct FullType {
130    pub kind: Option<__TypeKind>,
131    pub name: Option<String>,
132    pub description: Option<String>,
133    pub fields: Option<Vec<FullTypeFields>>,
134    pub input_fields: Option<Vec<FullTypeInputFields>>,
135    pub interfaces: Option<Vec<FullTypeInterfaces>>,
136    pub enum_values: Option<Vec<FullTypeEnumValues>>,
137    pub possible_types: Option<Vec<FullTypePossibleTypes>>,
138}
139
140#[derive(Clone, Debug, Deserialize)]
141#[serde(rename_all = "camelCase")]
142pub struct FullTypeFieldsArgs {
143    #[serde(flatten)]
144    #[allow(dead_code)]
145    input_value: InputValue,
146}
147
148#[derive(Clone, Debug, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct FullTypeFieldsType {
151    #[serde(flatten)]
152    pub type_ref: TypeRef,
153}
154
155#[derive(Clone, Debug, Deserialize)]
156#[serde(rename_all = "camelCase")]
157pub struct FullTypeFields {
158    pub name: Option<String>,
159    pub description: Option<String>,
160    pub args: Option<Vec<Option<FullTypeFieldsArgs>>>,
161    #[serde(rename = "type")]
162    pub type_: Option<FullTypeFieldsType>,
163    pub is_deprecated: Option<bool>,
164    pub deprecation_reason: Option<String>,
165}
166
167#[derive(Clone, Debug, Deserialize)]
168#[serde(rename_all = "camelCase")]
169pub struct FullTypeInputFields {
170    #[serde(flatten)]
171    pub input_value: InputValue,
172}
173
174#[derive(Clone, Debug, Deserialize)]
175#[serde(rename_all = "camelCase")]
176pub struct FullTypeInterfaces {
177    #[serde(flatten)]
178    pub type_ref: TypeRef,
179}
180
181#[derive(Clone, Debug, Deserialize)]
182#[serde(rename_all = "camelCase")]
183pub struct FullTypeEnumValues {
184    pub name: Option<String>,
185    pub description: Option<String>,
186    pub is_deprecated: Option<bool>,
187    pub deprecation_reason: Option<String>,
188}
189
190#[derive(Clone, Debug, Deserialize)]
191#[serde(rename_all = "camelCase")]
192pub struct FullTypePossibleTypes {
193    #[serde(flatten)]
194    pub type_ref: TypeRef,
195}
196
197#[derive(Clone, Debug, Deserialize)]
198#[serde(rename_all = "camelCase")]
199pub struct InputValue {
200    pub name: String,
201    pub description: Option<String>,
202    #[serde(rename = "type")]
203    pub type_: InputValueType,
204    pub default_value: Option<String>,
205    #[serde(default)]
206    pub is_deprecated: Option<bool>,
207    #[serde(default)]
208    pub deprecation_reason: Option<String>,
209}
210
211type InputValueType = TypeRef;
212
213#[derive(Clone, Debug, Deserialize)]
214#[serde(rename_all = "camelCase")]
215pub struct TypeRef {
216    pub kind: Option<__TypeKind>,
217    pub name: Option<String>,
218    pub of_type: Option<Box<TypeRef>>,
219}
220
221#[derive(Clone, Debug, Deserialize)]
222#[serde(rename_all = "camelCase")]
223pub struct SchemaQueryType {
224    pub name: Option<String>,
225}
226
227#[derive(Clone, Debug, Deserialize)]
228#[serde(rename_all = "camelCase")]
229pub struct SchemaMutationType {
230    pub name: Option<String>,
231}
232
233#[derive(Clone, Debug, Deserialize)]
234#[serde(rename_all = "camelCase")]
235pub struct SchemaSubscriptionType {
236    pub name: Option<String>,
237}
238
239#[derive(Clone, Debug, Deserialize)]
240#[serde(rename_all = "camelCase")]
241pub struct SchemaTypes {
242    #[serde(flatten)]
243    pub full_type: FullType,
244}
245
246#[derive(Clone, Debug, Deserialize)]
247#[serde(rename_all = "camelCase")]
248pub struct SchemaDirectivesArgs {
249    #[serde(flatten)]
250    #[allow(dead_code)]
251    input_value: InputValue,
252}
253
254#[derive(Clone, Debug, Deserialize)]
255#[serde(rename_all = "camelCase")]
256pub struct SchemaDirectives {
257    pub name: Option<String>,
258    pub description: Option<String>,
259    pub locations: Option<Vec<Option<__DirectiveLocation>>>,
260    pub args: Option<Vec<Option<SchemaDirectivesArgs>>>,
261}
262
263#[derive(Clone, Debug, Deserialize)]
264#[serde(rename_all = "camelCase")]
265pub struct Schema {
266    pub query_type: Option<SchemaQueryType>,
267    pub mutation_type: Option<SchemaMutationType>,
268    pub subscription_type: Option<SchemaSubscriptionType>,
269    pub types: Option<Vec<Option<SchemaTypes>>>,
270    #[allow(dead_code)]
271    directives: Option<Vec<Option<SchemaDirectives>>>,
272}
273
274#[derive(Clone, Debug, Deserialize)]
275pub struct SchemaContainer {
276    #[serde(rename = "__schema")]
277    pub schema: Option<Schema>,
278}
279
280#[derive(Deserialize, Debug)]
281pub struct FullResponse<T> {
282    data: T,
283}
284
285#[derive(Debug, Deserialize)]
286#[serde(untagged)]
287pub enum IntrospectionResponse {
288    FullResponse(FullResponse<SchemaContainer>),
289    Schema(SchemaContainer),
290}
291
292impl IntrospectionResponse {
293    pub fn as_schema(&self) -> &SchemaContainer {
294        match self {
295            IntrospectionResponse::FullResponse(full_response) => &full_response.data,
296            IntrospectionResponse::Schema(schema) => schema,
297        }
298    }
299
300    pub fn into_schema(self) -> SchemaContainer {
301        match self {
302            IntrospectionResponse::FullResponse(full_response) => full_response.data,
303            IntrospectionResponse::Schema(schema) => schema,
304        }
305    }
306}