-
Notifications
You must be signed in to change notification settings - Fork 1
/
grahql_types.go
242 lines (209 loc) · 7.3 KB
/
grahql_types.go
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
package yarql
import (
h "github.com/mjarkk/yarql/helpers"
)
//
// Types represent:
// https://spec.graphql.org/October2021/#sec-Schema-Introspection
//
var _ = TypeRename(qlSchema{}, "__Schema", true)
type qlSchema struct {
Types func() []qlType `json:"-"`
// For testing perposes mainly
JSONTypes []qlType `json:"types" gq:"-"`
QueryType *qlType `json:"queryType"`
MutationType *qlType `json:"mutationType"`
SubscriptionType *qlType `json:"subscriptionType"`
Directives []qlDirective `json:"directives"`
}
type isDeprecatedArgs struct {
IncludeDeprecated bool `json:"includeDeprecated"`
}
type __TypeKind uint8
const (
typeKindScalar __TypeKind = iota
typeKindObject
typeKindInterface
typeKindUnion
typeKindEnum
typeKindInputObject
typeKindList
typeKindNonNull
)
var typeKindEnumMap = map[string]__TypeKind{
"SCALAR": typeKindScalar,
"OBJECT": typeKindObject,
"INTERFACE": typeKindInterface,
"UNION": typeKindUnion,
"ENUM": typeKindEnum,
"INPUT_OBJECT": typeKindInputObject,
"LIST": typeKindList,
"NON_NULL": typeKindNonNull,
}
func (kind __TypeKind) String() string {
switch kind {
case typeKindScalar:
return "SCALAR"
case typeKindObject:
return "OBJECT"
case typeKindInterface:
return "INTERFACE"
case typeKindUnion:
return "UNION"
case typeKindEnum:
return "ENUM"
case typeKindInputObject:
return "INPUT_OBJECT"
case typeKindList:
return "LIST"
case typeKindNonNull:
return "NON_NULL"
}
return ""
}
var _ = TypeRename(qlType{}, "__Type", true)
// This type represents the graphql __Type type
// https://spec.graphql.org/October2021/#sec-Schema-Introspection
type qlType struct {
Kind __TypeKind `json:"-"`
Name *string `json:"name"`
Description *string `json:"description"`
// OBJECT and INTERFACE only
Fields func(isDeprecatedArgs) []qlField `json:"-"`
// OBJECT only
Interfaces []qlType `json:"interfaces"`
// INTERFACE and UNION only
PossibleTypes func() []qlType `json:"possibleTypes"`
// ENUM only
EnumValues func(isDeprecatedArgs) []qlEnumValue `json:"-"`
// INPUT_OBJECT only
InputFields func() []qlInputValue `json:"-"`
// NON_NULL and LIST only
OfType *qlType `json:"ofType"`
// SCALAR only
SpecifiedByURL *string `json:"specifiedByUrl"`
// For testing perposes
JSONKind string `json:"kind" gq:"-"`
JSONFields []qlField `json:"fields" gq:"-"`
JSONInputFields []qlField `json:"inputFields" gq:"-"`
}
var _ = TypeRename(qlField{}, "__Field", true)
type qlField struct {
Name string `json:"name"`
Description *string `json:"description"`
Args []qlInputValue `json:"args"`
Type qlType `json:"type"`
IsDeprecated bool `json:"isDeprecated"`
DeprecationReason *string `json:"deprecationReason"`
}
var _ = TypeRename(qlEnumValue{}, "__EnumValue", true)
type qlEnumValue struct {
Name string `json:"name"`
Description *string `json:"description"`
IsDeprecated bool `json:"isDeprecated"`
DeprecationReason *string `json:"deprecationReason"`
}
var _ = TypeRename(qlInputValue{}, "__InputValue", true)
type qlInputValue struct {
Name string `json:"name"`
Description *string `json:"description"`
Type qlType `json:"type"`
DefaultValue *string `json:"defaultValue"`
}
type __DirectiveLocation uint8
const (
directiveLocationQuery __DirectiveLocation = iota
directiveLocationMutation
directiveLocationSubscription
directiveLocationField
directiveLocationFragmentDefinition
directiveLocationFragmentSpread
directiveLocationInlineFragment
directiveLocationSchema
directiveLocationScalar
directiveLocationObject
directiveLocationFieldDefinition
directiveLocationArgumentDefinition
directiveLocationInterface
directiveLocationUnion
directiveLocationEnum
directiveLocationEnumValue
directiveLocationInputObject
directiveLocationInputFieldDefinition
)
var directiveLocationMap = map[string]__DirectiveLocation{
"QUERY": directiveLocationQuery,
"MUTATION": directiveLocationMutation,
"SUBSCRIPTION": directiveLocationSubscription,
"FIELD": directiveLocationField,
"FRAGMENT_DEFINITION": directiveLocationFragmentDefinition,
"FRAGMENT_SPREAD": directiveLocationFragmentSpread,
"INLINE_FRAGMENT": directiveLocationInlineFragment,
"SCHEMA": directiveLocationSchema,
"SCALAR": directiveLocationScalar,
"OBJECT": directiveLocationObject,
"FIELD_DEFINITION": directiveLocationFieldDefinition,
"ARGUMENT_DEFINITION": directiveLocationArgumentDefinition,
"INTERFACE": directiveLocationInterface,
"UNION": directiveLocationUnion,
"ENUM": directiveLocationEnum,
"ENUM_VALUE": directiveLocationEnumValue,
"INPUT_OBJECT": directiveLocationInputObject,
"INPUT_FIELD_DEFINITION": directiveLocationInputFieldDefinition,
}
var _ = TypeRename(qlDirective{}, "__Directive", true)
type qlDirective struct {
Name string `json:"name"`
Description *string `json:"description"`
Locations []__DirectiveLocation `json:"-"`
JSONLocations []string `json:"locations" gq:"-"`
Args []qlInputValue `json:"args"`
}
var (
scalarBoolean = qlType{
Kind: typeKindScalar,
Name: h.StrPtr("Boolean"),
Description: h.StrPtr("The `Boolean` scalar type represents `true` or `false`."),
}
scalarInt = qlType{
Kind: typeKindScalar,
Name: h.StrPtr("Int"),
Description: h.StrPtr("The Int scalar type represents a signed 32‐bit numeric non‐fractional value."),
}
scalarFloat = qlType{
Kind: typeKindScalar,
Name: h.StrPtr("Float"),
Description: h.StrPtr("The Float scalar type represents signed double‐precision fractional values as specified by IEEE 754."),
}
scalarString = qlType{
Kind: typeKindScalar,
Name: h.StrPtr("String"),
Description: h.StrPtr("The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text."),
}
scalarID = qlType{
Kind: typeKindScalar,
Name: h.StrPtr("ID"),
Description: h.StrPtr("The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache"),
}
scalarFile = qlType{
Kind: typeKindScalar,
Name: h.StrPtr("File"),
Description: h.StrPtr("The File scalar type references to a multipart file, often used to upload files to the server. Expects a string with the form file field name"),
SpecifiedByURL: h.StrPtr("https://github.com/mjarkk/yarql#file-upload"),
}
scalarTime = qlType{
Kind: typeKindScalar,
Name: h.StrPtr("Time"),
Description: h.StrPtr("The Time scalar type references to a ISO 8601 date+time, often used to insert and/or view dates. Expects a string with the ISO 8601 format"),
SpecifiedByURL: h.StrPtr("https://en.wikipedia.org/wiki/ISO_8601"),
}
)
var scalars = map[string]qlType{
"Boolean": scalarBoolean,
"Int": scalarInt,
"Float": scalarFloat,
"String": scalarString,
"ID": scalarID,
"File": scalarFile,
"Time": scalarTime,
}