1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#![allow(non_camel_case_types)]

use serde::{Deserialize, Deserializer, Serialize};

#[derive(Clone, Debug)]
pub enum __DirectiveLocation {
    QUERY,
    MUTATION,
    SUBSCRIPTION,
    FIELD,
    FRAGMENT_DEFINITION,
    FRAGMENT_SPREAD,
    INLINE_FRAGMENT,
    SCHEMA,
    SCALAR,
    OBJECT,
    FIELD_DEFINITION,
    ARGUMENT_DEFINITION,
    INTERFACE,
    UNION,
    ENUM,
    ENUM_VALUE,
    INPUT_OBJECT,
    INPUT_FIELD_DEFINITION,
    Other(String),
}

impl Serialize for __DirectiveLocation {
    fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
        ser.serialize_str(match *self {
            __DirectiveLocation::QUERY => "QUERY",
            __DirectiveLocation::MUTATION => "MUTATION",
            __DirectiveLocation::SUBSCRIPTION => "SUBSCRIPTION",
            __DirectiveLocation::FIELD => "FIELD",
            __DirectiveLocation::FRAGMENT_DEFINITION => "FRAGMENT_DEFINITION",
            __DirectiveLocation::FRAGMENT_SPREAD => "FRAGMENT_SPREAD",
            __DirectiveLocation::INLINE_FRAGMENT => "INLINE_FRAGMENT",
            __DirectiveLocation::SCHEMA => "SCHEMA",
            __DirectiveLocation::SCALAR => "SCALAR",
            __DirectiveLocation::OBJECT => "OBJECT",
            __DirectiveLocation::FIELD_DEFINITION => "FIELD_DEFINITION",
            __DirectiveLocation::ARGUMENT_DEFINITION => "ARGUMENT_DEFINITION",
            __DirectiveLocation::INTERFACE => "INTERFACE",
            __DirectiveLocation::UNION => "UNION",
            __DirectiveLocation::ENUM => "ENUM",
            __DirectiveLocation::ENUM_VALUE => "ENUM_VALUE",
            __DirectiveLocation::INPUT_OBJECT => "INPUT_OBJECT",
            __DirectiveLocation::INPUT_FIELD_DEFINITION => "INPUT_FIELD_DEFINITION",
            __DirectiveLocation::Other(ref s) => s.as_str(),
        })
    }
}

impl<'de> Deserialize<'de> for __DirectiveLocation {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = <&'de str>::deserialize(deserializer)?;
        match s {
            "QUERY" => Ok(__DirectiveLocation::QUERY),
            "MUTATION" => Ok(__DirectiveLocation::MUTATION),
            "SUBSCRIPTION" => Ok(__DirectiveLocation::SUBSCRIPTION),
            "FIELD" => Ok(__DirectiveLocation::FIELD),
            "FRAGMENT_DEFINITION" => Ok(__DirectiveLocation::FRAGMENT_DEFINITION),
            "FRAGMENT_SPREAD" => Ok(__DirectiveLocation::FRAGMENT_SPREAD),
            "INLINE_FRAGMENT" => Ok(__DirectiveLocation::INLINE_FRAGMENT),
            "SCHEMA" => Ok(__DirectiveLocation::SCHEMA),
            "SCALAR" => Ok(__DirectiveLocation::SCALAR),
            "OBJECT" => Ok(__DirectiveLocation::OBJECT),
            "FIELD_DEFINITION" => Ok(__DirectiveLocation::FIELD_DEFINITION),
            "ARGUMENT_DEFINITION" => Ok(__DirectiveLocation::ARGUMENT_DEFINITION),
            "INTERFACE" => Ok(__DirectiveLocation::INTERFACE),
            "UNION" => Ok(__DirectiveLocation::UNION),
            "ENUM" => Ok(__DirectiveLocation::ENUM),
            "ENUM_VALUE" => Ok(__DirectiveLocation::ENUM_VALUE),
            "INPUT_OBJECT" => Ok(__DirectiveLocation::INPUT_OBJECT),
            "INPUT_FIELD_DEFINITION" => Ok(__DirectiveLocation::INPUT_FIELD_DEFINITION),
            _ => Ok(__DirectiveLocation::Other(s.to_string())),
        }
    }
}

#[derive(Clone, Debug, PartialEq)]
pub enum __TypeKind {
    SCALAR,
    OBJECT,
    INTERFACE,
    UNION,
    ENUM,
    INPUT_OBJECT,
    LIST,
    NON_NULL,
    Other(String),
}

impl Serialize for __TypeKind {
    fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
        ser.serialize_str(match *self {
            __TypeKind::SCALAR => "SCALAR",
            __TypeKind::OBJECT => "OBJECT",
            __TypeKind::INTERFACE => "INTERFACE",
            __TypeKind::UNION => "UNION",
            __TypeKind::ENUM => "ENUM",
            __TypeKind::INPUT_OBJECT => "INPUT_OBJECT",
            __TypeKind::LIST => "LIST",
            __TypeKind::NON_NULL => "NON_NULL",
            __TypeKind::Other(ref s) => s.as_str(),
        })
    }
}

impl<'de> Deserialize<'de> for __TypeKind {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = <&'de str>::deserialize(deserializer)?;
        match s {
            "SCALAR" => Ok(__TypeKind::SCALAR),
            "OBJECT" => Ok(__TypeKind::OBJECT),
            "INTERFACE" => Ok(__TypeKind::INTERFACE),
            "UNION" => Ok(__TypeKind::UNION),
            "ENUM" => Ok(__TypeKind::ENUM),
            "INPUT_OBJECT" => Ok(__TypeKind::INPUT_OBJECT),
            "LIST" => Ok(__TypeKind::LIST),
            "NON_NULL" => Ok(__TypeKind::NON_NULL),
            _ => Ok(__TypeKind::Other(s.to_string())),
        }
    }
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FullType {
    pub kind: Option<__TypeKind>,
    pub name: Option<String>,
    pub description: Option<String>,
    pub fields: Option<Vec<FullTypeFields>>,
    pub input_fields: Option<Vec<FullTypeInputFields>>,
    pub interfaces: Option<Vec<FullTypeInterfaces>>,
    pub enum_values: Option<Vec<FullTypeEnumValues>>,
    pub possible_types: Option<Vec<FullTypePossibleTypes>>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FullTypeFieldsArgs {
    #[serde(flatten)]
    input_value: InputValue,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FullTypeFieldsType {
    #[serde(flatten)]
    pub type_ref: TypeRef,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FullTypeFields {
    pub name: Option<String>,
    pub description: Option<String>,
    pub args: Option<Vec<Option<FullTypeFieldsArgs>>>,
    #[serde(rename = "type")]
    pub type_: Option<FullTypeFieldsType>,
    pub is_deprecated: Option<bool>,
    pub deprecation_reason: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FullTypeInputFields {
    #[serde(flatten)]
    pub input_value: InputValue,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FullTypeInterfaces {
    #[serde(flatten)]
    pub type_ref: TypeRef,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FullTypeEnumValues {
    pub name: Option<String>,
    pub description: Option<String>,
    pub is_deprecated: Option<bool>,
    pub deprecation_reason: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FullTypePossibleTypes {
    #[serde(flatten)]
    pub type_ref: TypeRef,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InputValue {
    pub name: String,
    pub description: Option<String>,
    #[serde(rename = "type")]
    pub type_: InputValueType,
    pub default_value: Option<String>,
}

type InputValueType = TypeRef;

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TypeRef {
    pub kind: Option<__TypeKind>,
    pub name: Option<String>,
    pub of_type: Option<Box<TypeRef>>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SchemaQueryType {
    pub name: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SchemaMutationType {
    pub name: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SchemaSubscriptionType {
    pub name: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SchemaTypes {
    #[serde(flatten)]
    pub full_type: FullType,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SchemaDirectivesArgs {
    #[serde(flatten)]
    input_value: InputValue,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SchemaDirectives {
    pub name: Option<String>,
    pub description: Option<String>,
    pub locations: Option<Vec<Option<__DirectiveLocation>>>,
    pub args: Option<Vec<Option<SchemaDirectivesArgs>>>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Schema {
    pub query_type: Option<SchemaQueryType>,
    pub mutation_type: Option<SchemaMutationType>,
    pub subscription_type: Option<SchemaSubscriptionType>,
    pub types: Option<Vec<Option<SchemaTypes>>>,
    directives: Option<Vec<Option<SchemaDirectives>>>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct SchemaContainer {
    #[serde(rename = "__schema")]
    pub schema: Option<Schema>,
}

#[derive(Deserialize, Debug)]
pub struct FullResponse<T> {
    data: T,
}

#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum IntrospectionResponse {
    FullResponse(FullResponse<SchemaContainer>),
    Schema(SchemaContainer),
}

impl IntrospectionResponse {
    pub fn as_schema(&self) -> &SchemaContainer {
        match self {
            IntrospectionResponse::FullResponse(full_response) => &full_response.data,
            IntrospectionResponse::Schema(schema) => schema,
        }
    }

    pub fn into_schema(self) -> SchemaContainer {
        match self {
            IntrospectionResponse::FullResponse(full_response) => full_response.data,
            IntrospectionResponse::Schema(schema) => schema,
        }
    }
}