Skip to content

Commit 66e5112

Browse files
committed
fix for introspection structs
1 parent 7cd231b commit 66e5112

File tree

1 file changed

+63
-50
lines changed

1 file changed

+63
-50
lines changed

src/introspection/introspection.rs

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,95 +5,95 @@ use serde_json::Result;
55

66
#[derive(Serialize, Deserialize, Debug)]
77
pub struct IntrospectionQuery {
8-
__schema: IntrospectionSchema,
8+
pub __schema: IntrospectionSchema,
99
}
1010

1111
#[derive(Serialize, Deserialize, Debug)]
1212
pub struct IntrospectionScalarType {
13-
name: String,
14-
description: Option<String>,
13+
pub name: String,
14+
pub description: Option<String>,
1515
#[serde(rename = "specifiedByURL")]
16-
specified_by_url: Option<String>,
16+
pub specified_by_url: Option<String>,
1717
}
1818

1919
#[derive(Serialize, Deserialize, Debug)]
2020
pub struct IntrospectionInputValue {
21-
name: String,
22-
description: Option<String>,
21+
pub name: String,
22+
pub description: Option<String>,
2323
#[serde(rename = "defaultValue")]
24-
default_value: Option<String>,
24+
pub default_value: Option<String>,
2525
#[serde(rename = "isDeprecated")]
26-
is_deprecated: Option<bool>,
26+
pub is_deprecated: Option<bool>,
2727
#[serde(rename = "deprecationReason")]
28-
deprecation_reason: Option<String>,
28+
pub deprecation_reason: Option<String>,
2929
#[serde(rename = "type")]
30-
type_ref: Option<IntrospectionInputTypeRef>,
30+
pub type_ref: Option<IntrospectionInputTypeRef>,
3131
}
3232

3333
#[derive(Serialize, Deserialize, Debug)]
3434
#[serde(tag = "kind")]
3535
pub struct IntrospectionField {
36-
name: String,
37-
description: Option<String>,
38-
args: Vec<IntrospectionInputValue>,
36+
pub name: String,
37+
pub description: Option<String>,
38+
pub args: Vec<IntrospectionInputValue>,
3939
#[serde(rename = "isDeprecated")]
40-
is_deprecated: Option<bool>,
40+
pub is_deprecated: Option<bool>,
4141
#[serde(rename = "deprecationReason")]
42-
deprecation_reason: Option<String>,
42+
pub deprecation_reason: Option<String>,
4343
#[serde(rename = "type")]
44-
type_ref: IntrospectionOutputTypeRef,
44+
pub type_ref: IntrospectionOutputTypeRef,
4545
}
4646

4747
#[derive(Serialize, Deserialize, Debug)]
4848
pub struct IntrospectionObjectType {
49-
name: String,
50-
description: Option<String>,
51-
fields: Vec<IntrospectionField>,
52-
interfaces: Vec<IntrospectionNamedTypeRef>,
49+
pub name: String,
50+
pub description: Option<String>,
51+
pub fields: Vec<IntrospectionField>,
52+
pub interfaces: Vec<IntrospectionNamedTypeRef>,
5353
}
5454

5555
#[derive(Serialize, Deserialize, Debug)]
5656
pub struct IntrospectionInterfaceType {
57-
name: String,
58-
description: Option<String>,
59-
fields: Vec<IntrospectionField>,
60-
interfaces: Option<Vec<IntrospectionNamedTypeRef>>,
57+
pub name: String,
58+
pub description: Option<String>,
59+
pub fields: Vec<IntrospectionField>,
60+
pub interfaces: Option<Vec<IntrospectionNamedTypeRef>>,
6161
#[serde(rename = "possibleTypes")]
62-
possible_types: Vec<IntrospectionNamedTypeRef>,
62+
pub possible_types: Vec<IntrospectionNamedTypeRef>,
6363
}
6464

6565
#[derive(Serialize, Deserialize, Debug)]
6666
pub struct IntrospectionUnionType {
67-
name: String,
68-
description: Option<String>,
67+
pub name: String,
68+
pub description: Option<String>,
6969
#[serde(rename = "possibleTypes")]
70-
possible_types: Vec<IntrospectionNamedTypeRef>,
70+
pub possible_types: Vec<IntrospectionNamedTypeRef>,
7171
}
7272

7373
#[derive(Serialize, Deserialize, Debug)]
7474
pub struct IntrospectionEnumValue {
75-
name: String,
76-
description: Option<String>,
75+
pub name: String,
76+
pub description: Option<String>,
7777
#[serde(rename = "isDeprecated")]
78-
is_deprecated: Option<bool>,
78+
pub is_deprecated: Option<bool>,
7979
#[serde(rename = "deprecationReason")]
80-
deprecation_reason: Option<String>,
80+
pub deprecation_reason: Option<String>,
8181
}
8282

8383
#[derive(Serialize, Deserialize, Debug)]
8484
pub struct IntrospectionEnumType {
85-
name: String,
86-
description: Option<String>,
85+
pub name: String,
86+
pub description: Option<String>,
8787
#[serde(rename = "enumValues")]
88-
enum_values: Vec<IntrospectionEnumValue>,
88+
pub enum_values: Vec<IntrospectionEnumValue>,
8989
}
9090

9191
#[derive(Serialize, Deserialize, Debug)]
9292
pub struct IntrospectionInputObjectType {
93-
name: String,
94-
description: Option<String>,
93+
pub name: String,
94+
pub description: Option<String>,
9595
#[serde(rename = "inputFields")]
96-
input_fields: Vec<IntrospectionInputValue>,
96+
pub input_fields: Vec<IntrospectionInputValue>,
9797
}
9898

9999
#[derive(Serialize, Deserialize, Debug)]
@@ -107,6 +107,19 @@ pub enum IntrospectionType {
107107
INPUT_OBJECT(IntrospectionInputObjectType),
108108
}
109109

110+
impl IntrospectionType {
111+
pub fn name(&self) -> &String {
112+
match &self {
113+
IntrospectionType::ENUM(e) => &e.name,
114+
IntrospectionType::OBJECT(o) => &o.name,
115+
IntrospectionType::INPUT_OBJECT(io) => &io.name,
116+
IntrospectionType::INTERFACE(i) => &i.name,
117+
IntrospectionType::SCALAR(s) => &s.name,
118+
IntrospectionType::UNION(u) => &u.name,
119+
}
120+
}
121+
}
122+
110123
#[derive(Serialize, Deserialize, Debug)]
111124
#[serde(tag = "kind")]
112125
pub enum IntrospectionInputType {
@@ -127,7 +140,7 @@ pub enum IntrospectionOutputType {
127140

128141
#[derive(Serialize, Deserialize, Debug)]
129142
pub struct IntrospectionNamedTypeRef {
130-
name: String,
143+
pub name: String,
131144
}
132145

133146
#[derive(Serialize, Deserialize, Debug)]
@@ -167,15 +180,15 @@ pub enum IntrospectionInputTypeRef {
167180

168181
#[derive(Serialize, Deserialize, Debug)]
169182
pub struct IntrospectionSchema {
170-
description: Option<String>,
183+
pub description: Option<String>,
171184
#[serde(rename = "queryType")]
172-
query_type: IntrospectionNamedTypeRef,
185+
pub query_type: IntrospectionNamedTypeRef,
173186
#[serde(rename = "mutationType")]
174-
mutation_type: Option<IntrospectionNamedTypeRef>,
187+
pub mutation_type: Option<IntrospectionNamedTypeRef>,
175188
#[serde(rename = "subscriptionType")]
176-
subscription_type: Option<IntrospectionNamedTypeRef>,
177-
types: Vec<IntrospectionType>,
178-
directives: Vec<IntrospectionDirective>,
189+
pub subscription_type: Option<IntrospectionNamedTypeRef>,
190+
pub types: Vec<IntrospectionType>,
191+
pub directives: Vec<IntrospectionDirective>,
179192
}
180193

181194
#[derive(Serialize, Deserialize, Debug)]
@@ -204,12 +217,12 @@ pub enum DirectiveLocation {
204217

205218
#[derive(Serialize, Deserialize, Debug)]
206219
pub struct IntrospectionDirective {
207-
name: String,
208-
description: Option<String>,
220+
pub name: String,
221+
pub description: Option<String>,
209222
#[serde(rename = "isRepeatable")]
210-
is_repeatable: Option<bool>,
211-
locations: Vec<DirectiveLocation>,
212-
args: Vec<IntrospectionInputValue>,
223+
pub is_repeatable: Option<bool>,
224+
pub locations: Vec<DirectiveLocation>,
225+
pub args: Vec<IntrospectionInputValue>,
213226
}
214227

215228
pub fn parse_introspection<R>(input: R) -> Result<IntrospectionQuery>

0 commit comments

Comments
 (0)