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)]
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 pub input_value: InputValue,
145}
146
147#[derive(Clone, Debug, Deserialize)]
148#[serde(rename_all = "camelCase")]
149pub struct FullTypeFieldsType {
150 #[serde(flatten)]
151 pub type_ref: TypeRef,
152}
153
154#[derive(Clone, Debug, Deserialize)]
155#[serde(rename_all = "camelCase")]
156pub struct FullTypeFields {
157 pub name: Option<String>,
158 pub description: Option<String>,
159 pub args: Option<Vec<Option<FullTypeFieldsArgs>>>,
160 #[serde(rename = "type")]
161 pub type_: Option<FullTypeFieldsType>,
162 pub is_deprecated: Option<bool>,
163 pub deprecation_reason: Option<String>,
164
165 #[serde(skip)]
166 pub parent_type: Option<FullType>,
167}
168
169#[derive(Clone, Debug, Deserialize)]
170#[serde(rename_all = "camelCase")]
171pub struct FullTypeInputFields {
172 #[serde(flatten)]
173 pub input_value: InputValue,
174}
175
176#[derive(Clone, Debug, Deserialize)]
177#[serde(rename_all = "camelCase")]
178pub struct FullTypeInterfaces {
179 #[serde(flatten)]
180 pub type_ref: TypeRef,
181}
182
183#[derive(Clone, Debug, Deserialize)]
184#[serde(rename_all = "camelCase")]
185pub struct FullTypeEnumValues {
186 pub name: Option<String>,
187 pub description: Option<String>,
188 pub is_deprecated: Option<bool>,
189 pub deprecation_reason: Option<String>,
190}
191
192#[derive(Clone, Debug, Deserialize)]
193#[serde(rename_all = "camelCase")]
194pub struct FullTypePossibleTypes {
195 #[serde(flatten)]
196 pub type_ref: TypeRef,
197}
198
199#[derive(Clone, Debug, Deserialize)]
200#[serde(rename_all = "camelCase")]
201pub struct InputValue {
202 pub name: String,
203 pub description: Option<String>,
204 #[serde(rename = "type")]
205 pub type_: InputValueType,
206 pub default_value: Option<String>,
207}
208
209type InputValueType = TypeRef;
210
211#[derive(Clone, Debug, Deserialize)]
212#[serde(rename_all = "camelCase")]
213pub struct TypeRef {
214 pub kind: Option<__TypeKind>,
215 pub name: Option<String>,
216 pub of_type: Option<Box<TypeRef>>,
217}
218
219#[derive(Clone, Debug, Deserialize)]
220#[serde(rename_all = "camelCase")]
221pub struct SchemaQueryType {
222 pub name: Option<String>,
223}
224
225#[derive(Clone, Debug, Deserialize)]
226#[serde(rename_all = "camelCase")]
227pub struct SchemaMutationType {
228 pub name: Option<String>,
229}
230
231#[derive(Clone, Debug, Deserialize)]
232#[serde(rename_all = "camelCase")]
233pub struct SchemaSubscriptionType {
234 pub name: Option<String>,
235}
236
237#[derive(Clone, Debug, Deserialize)]
238#[serde(rename_all = "camelCase")]
239pub struct SchemaTypes {
240 #[serde(flatten)]
241 pub full_type: FullType,
242}
243
244#[allow(dead_code)]
245#[derive(Clone, Debug, Deserialize)]
246#[serde(rename_all = "camelCase")]
247pub struct SchemaDirectivesArgs {
248 #[serde(flatten)]
249 input_value: InputValue,
250}
251
252#[derive(Clone, Debug, Deserialize)]
253#[serde(rename_all = "camelCase")]
254pub struct SchemaDirectives {
255 pub name: Option<String>,
256 pub description: Option<String>,
257 pub locations: Option<Vec<Option<__DirectiveLocation>>>,
258 pub args: Option<Vec<Option<SchemaDirectivesArgs>>>,
259}
260
261#[allow(dead_code)]
262#[derive(Clone, Debug, Deserialize)]
263#[serde(rename_all = "camelCase")]
264pub struct Schema {
265 pub query_type: Option<SchemaQueryType>,
266 pub mutation_type: Option<SchemaMutationType>,
267 pub subscription_type: Option<SchemaSubscriptionType>,
268 pub types: Option<Vec<Option<SchemaTypes>>>,
269 directives: Option<Vec<Option<SchemaDirectives>>>,
270}
271
272#[derive(Clone, Debug, Deserialize)]
273pub struct SchemaContainer {
274 #[serde(rename = "__schema")]
275 pub schema: Option<Schema>,
276}
277
278#[derive(Deserialize, Debug)]
279pub struct FullResponse<T> {
280 data: T,
281}
282
283#[derive(Debug, Deserialize)]
284#[serde(untagged)]
285pub enum IntrospectionResponse {
286 FullResponse(FullResponse<SchemaContainer>),
287 Schema(SchemaContainer),
288}
289
290impl IntrospectionResponse {
291 pub fn as_schema(&self) -> &SchemaContainer {
292 match self {
293 IntrospectionResponse::FullResponse(full_response) => &full_response.data,
294 IntrospectionResponse::Schema(schema) => schema,
295 }
296 }
297
298 pub fn into_schema(self) -> SchemaContainer {
299 match self {
300 IntrospectionResponse::FullResponse(full_response) => full_response.data,
301 IntrospectionResponse::Schema(schema) => schema,
302 }
303 }
304}