Skip to content

Commit 9a9c143

Browse files
Fix GraphQL types
1 parent 7673e78 commit 9a9c143

File tree

1 file changed

+75
-19
lines changed

1 file changed

+75
-19
lines changed

cmd/sortSchema/graphql/types.go

+75-19
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ type Data struct {
2626
// operation.
2727
// See https://spec.graphql.org/June2018/#sec-Schema-Introspection
2828
type __Schema struct {
29-
Types []__Type `json:"types"`
30-
QueryType SchemaType `json:"queryType"`
31-
MutationType SchemaType `json:"mutationType"`
32-
SubscriptionType SchemaType `json:"subscriptionType"`
33-
Directives []__Directive `json:"directives"`
29+
Types []__ObjectType `json:"types"`
30+
QueryType SchemaType `json:"queryType"`
31+
MutationType SchemaType `json:"mutationType"`
32+
SubscriptionType SchemaType `json:"subscriptionType"`
33+
Directives []__Directive `json:"directives"`
3434
}
3535

3636
// Sort the child arrays of Schema
@@ -68,29 +68,29 @@ func (s *__Schema) Sort() {
6868
// See https://spec.graphql.org/June2018/#sec-The-__Type-Type
6969
type __Type struct {
7070
Kind __TypeKind `json:"kind"`
71-
Name string `json:"name,omitempty"`
72-
Description string `json:"description,omitempty"`
71+
Name string `json:"name"`
72+
Description string `json:"description"`
7373

7474
// OBJECT and INTERFACE only
75-
Fields []__Field `json:"fields,omitempty"`
75+
Fields []__Field `json:"fields"`
7676

7777
// OBJECT only
78-
Interfaces []__Type `json:"interfaces,omitempty"`
78+
Interfaces []__Type `json:"interfaces"`
7979

8080
// INTERFACE and UNION only
81-
PossibleTypes []__Type `json:"possibleTypes,omitempty"`
81+
PossibleTypes []__Type `json:"possibleTypes"`
8282

8383
// ENUM only
84-
EnumValues []EnumValue `json:"enumValue,omitempty"`
84+
EnumValues []EnumValue `json:"enumValues"`
8585

8686
// INPUT_OBJECT only
87-
InputFields []__InputValue `json:"inputFields,omitempty"`
87+
InputFields []__InputValue `json:"inputFields"`
8888

8989
// NON_NULL and LIST only
9090
OfType *__Type `json:"ofType,omitempty"`
9191
}
9292

93-
// Sort the child arrays of GraphQLType
93+
// Sort the child arrays of __Type
9494
func (t *__Type) Sort() {
9595
sort.Slice(t.Fields, func(i, j int) bool {
9696
return t.Fields[i].Name < t.Fields[j].Name
@@ -124,6 +124,62 @@ func (t *__Type) Sort() {
124124
})
125125
}
126126

127+
// Similar to __Type but without OfType
128+
type __ObjectType struct {
129+
Kind __TypeKind `json:"kind"`
130+
Name string `json:"name"`
131+
Description string `json:"description"`
132+
133+
// OBJECT and INTERFACE only
134+
Fields []__Field `json:"fields"`
135+
136+
// OBJECT only
137+
Interfaces []__Type `json:"interfaces"`
138+
139+
// INTERFACE and UNION only
140+
PossibleTypes []__Type `json:"possibleTypes"`
141+
142+
// ENUM only
143+
EnumValues []EnumValue `json:"enumValues"`
144+
145+
// INPUT_OBJECT only
146+
InputFields []__InputValue `json:"inputFields"`
147+
}
148+
149+
// Sort the child arrays of __ObjectType
150+
func (t *__ObjectType) Sort() {
151+
sort.Slice(t.Fields, func(i, j int) bool {
152+
return t.Fields[i].Name < t.Fields[j].Name
153+
})
154+
for i := range t.Fields {
155+
sort.Slice(t.Fields[i].Args, func(j, k int) bool {
156+
return t.Fields[i].Args[j].Name < t.Fields[i].Args[k].Name
157+
})
158+
}
159+
160+
sort.Slice(t.Interfaces, func(i, j int) bool {
161+
return t.Interfaces[i].Name < t.Interfaces[j].Name
162+
})
163+
for i := range t.Interfaces {
164+
t.Interfaces[i].Sort()
165+
}
166+
167+
sort.Slice(t.PossibleTypes, func(i, j int) bool {
168+
return t.PossibleTypes[i].Name < t.PossibleTypes[j].Name
169+
})
170+
for i := range t.PossibleTypes {
171+
t.PossibleTypes[i].Sort()
172+
}
173+
174+
sort.Slice(t.EnumValues, func(i, j int) bool {
175+
return t.EnumValues[i].Name < t.EnumValues[j].Name
176+
})
177+
178+
sort.Slice(t.InputFields, func(i, j int) bool {
179+
return t.InputFields[i].Name < t.InputFields[j].Name
180+
})
181+
}
182+
127183
// There are several different kinds of type. In each kind, different fields
128184
// are actually valid. These kinds are listed in the __TypeKind enumeration.
129185
//
@@ -145,22 +201,22 @@ const (
145201
// See https://spec.graphql.org/June2018/#sec-The-__Field-Type
146202
type __Field struct {
147203
Name string `json:"name,omitempty"`
148-
Description string `json:"description,omitempty"`
204+
Description string `json:"description"`
149205
Args []__InputValue `json:"args"`
150206
Type __Type `json:"type"`
151207
IsDeprecated bool `json:"isDeprecated"`
152-
DeprecationReason string `json:"deprecationReason,omitempty"`
208+
DeprecationReason *string `json:"deprecationReason"`
153209
}
154210

155211
// The __InputValue type represents field and directive arguments as well as
156212
// the inputFields of an input object.
157213
//
158214
// See https://spec.graphql.org/June2018/#sec-The-__InputValue-Type
159215
type __InputValue struct {
160-
Name string `json:"name"`
161-
Description string `json:"description,omitempty"`
162-
Type __Type `json:"type"`
163-
DefaultValue string `json:"defaultValue"`
216+
Name string `json:"name"`
217+
Description string `json:"description,omitempty"`
218+
Type __Type `json:"type"`
219+
DefaultValue *string `json:"defaultValue"`
164220
}
165221

166222
// The __EnumValue type represents one of possible values of an enum.

0 commit comments

Comments
 (0)