Skip to content

Commit a19ac6c

Browse files
committed
Export introspection in public API
Commit: 71b6a4aaecf064c7095bca81cc4285fa74ba175e [71b6a4a] Parents: 980bdf403f Author: Lee Byron <[email protected]> Date: 7 May 2016 at 4:26:20 AM SGT
1 parent 8c1f318 commit a19ac6c

File tree

1 file changed

+63
-42
lines changed

1 file changed

+63
-42
lines changed

introspection.go

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,44 @@ const (
1919
TypeKindNonNull = "NON_NULL"
2020
)
2121

22-
var directiveType *Object
23-
var schemaType *Object
24-
var typeType *Object
25-
var fieldType *Object
26-
var inputValueType *Object
27-
var enumValueType *Object
22+
// SchemaType is type definition for __Schema
23+
var SchemaType *Object
2824

29-
var typeKindEnum *Enum
30-
var directiveLocationEnum *Enum
25+
// DirectiveType is type definition for __Directive
26+
var DirectiveType *Object
3127

28+
// TypeType is type definition for __Type
29+
var TypeType *Object
30+
31+
// FieldType is type definition for __Field
32+
var FieldType *Object
33+
34+
// InputValueType is type definition for __InputValue
35+
var InputValueType *Object
36+
37+
// EnumValueType is type definition for __EnumValue
38+
var EnumValueType *Object
39+
40+
// TypeKindEnumType is type definition for __TypeKind
41+
var TypeKindEnumType *Enum
42+
43+
// DirectiveLocationEnumType is type definition for __DirectiveLocation
44+
var DirectiveLocationEnumType *Enum
45+
46+
// Meta-field definitions.
47+
48+
// SchemaMetaFieldDef Meta field definition for Schema
3249
var SchemaMetaFieldDef *FieldDefinition
50+
51+
// TypeMetaFieldDef Meta field definition for types
3352
var TypeMetaFieldDef *FieldDefinition
53+
54+
// TypeNameMetaFieldDef Meta field definition for type names
3455
var TypeNameMetaFieldDef *FieldDefinition
3556

3657
func init() {
3758

38-
typeKindEnum = NewEnum(EnumConfig{
59+
TypeKindEnumType = NewEnum(EnumConfig{
3960
Name: "__TypeKind",
4061
Description: "An enum describing what kind of type a given `__Type` is",
4162
Values: EnumValueConfigMap{
@@ -81,7 +102,7 @@ func init() {
81102
},
82103
})
83104

84-
directiveLocationEnum = NewEnum(EnumConfig{
105+
DirectiveLocationEnumType = NewEnum(EnumConfig{
85106
Name: "__DirectiveLocation",
86107
Description: "A Directive can be adjacent to many parts of the GraphQL language, a " +
87108
"__DirectiveLocation describes one such possible adjacencies.",
@@ -118,7 +139,7 @@ func init() {
118139
})
119140

120141
// Note: some fields (for e.g "fields", "interfaces") are defined later due to cyclic reference
121-
typeType = NewObject(ObjectConfig{
142+
TypeType = NewObject(ObjectConfig{
122143
Name: "__Type",
123144
Description: "The fundamental unit of any GraphQL Schema is the type. There are " +
124145
"many kinds of types in GraphQL as represented by the `__TypeKind` enum." +
@@ -131,7 +152,7 @@ func init() {
131152

132153
Fields: Fields{
133154
"kind": &Field{
134-
Type: NewNonNull(typeKindEnum),
155+
Type: NewNonNull(TypeKindEnumType),
135156
Resolve: func(p ResolveParams) (interface{}, error) {
136157
switch p.Source.(type) {
137158
case *Scalar:
@@ -169,7 +190,7 @@ func init() {
169190
},
170191
})
171192

172-
inputValueType = NewObject(ObjectConfig{
193+
InputValueType = NewObject(ObjectConfig{
173194
Name: "__InputValue",
174195
Description: "Arguments provided to Fields or Directives and the input fields of an " +
175196
"InputObject are represented as Input Values which describe their type " +
@@ -182,7 +203,7 @@ func init() {
182203
Type: String,
183204
},
184205
"type": &Field{
185-
Type: NewNonNull(typeType),
206+
Type: NewNonNull(TypeType),
186207
},
187208
"defaultValue": &Field{
188209
Type: String,
@@ -212,7 +233,7 @@ func init() {
212233
},
213234
})
214235

215-
fieldType = NewObject(ObjectConfig{
236+
FieldType = NewObject(ObjectConfig{
216237
Name: "__Field",
217238
Description: "Object and Interface types are described by a list of Fields, each of " +
218239
"which has a name, potentially a list of arguments, and a return type.",
@@ -224,7 +245,7 @@ func init() {
224245
Type: String,
225246
},
226247
"args": &Field{
227-
Type: NewNonNull(NewList(NewNonNull(inputValueType))),
248+
Type: NewNonNull(NewList(NewNonNull(InputValueType))),
228249
Resolve: func(p ResolveParams) (interface{}, error) {
229250
if field, ok := p.Source.(*FieldDefinition); ok {
230251
return field.Args, nil
@@ -233,7 +254,7 @@ func init() {
233254
},
234255
},
235256
"type": &Field{
236-
Type: NewNonNull(typeType),
257+
Type: NewNonNull(TypeType),
237258
},
238259
"isDeprecated": &Field{
239260
Type: NewNonNull(Boolean),
@@ -250,7 +271,7 @@ func init() {
250271
},
251272
})
252273

253-
directiveType = NewObject(ObjectConfig{
274+
DirectiveType = NewObject(ObjectConfig{
254275
Name: "__Directive",
255276
Description: "A Directive provides a way to describe alternate runtime execution and " +
256277
"type validation behavior in a GraphQL document. " +
@@ -267,12 +288,12 @@ func init() {
267288
},
268289
"locations": &Field{
269290
Type: NewNonNull(NewList(
270-
NewNonNull(directiveLocationEnum),
291+
NewNonNull(DirectiveLocationEnumType),
271292
)),
272293
},
273294
"args": &Field{
274295
Type: NewNonNull(NewList(
275-
NewNonNull(inputValueType),
296+
NewNonNull(InputValueType),
276297
)),
277298
},
278299
// NOTE: the following three fields are deprecated and are no longer part
@@ -335,7 +356,7 @@ func init() {
335356
},
336357
})
337358

338-
schemaType = NewObject(ObjectConfig{
359+
SchemaType = NewObject(ObjectConfig{
339360
Name: "__Schema",
340361
Description: `A GraphQL Schema defines the capabilities of a GraphQL server. ` +
341362
`It exposes all available types and directives on the server, as well as ` +
@@ -344,7 +365,7 @@ func init() {
344365
"types": &Field{
345366
Description: "A list of all types supported by this server.",
346367
Type: NewNonNull(NewList(
347-
NewNonNull(typeType),
368+
NewNonNull(TypeType),
348369
)),
349370
Resolve: func(p ResolveParams) (interface{}, error) {
350371
if schema, ok := p.Source.(Schema); ok {
@@ -359,7 +380,7 @@ func init() {
359380
},
360381
"queryType": &Field{
361382
Description: "The type that query operations will be rooted at.",
362-
Type: NewNonNull(typeType),
383+
Type: NewNonNull(TypeType),
363384
Resolve: func(p ResolveParams) (interface{}, error) {
364385
if schema, ok := p.Source.(Schema); ok {
365386
return schema.QueryType(), nil
@@ -370,7 +391,7 @@ func init() {
370391
"mutationType": &Field{
371392
Description: `If this server supports mutation, the type that ` +
372393
`mutation operations will be rooted at.`,
373-
Type: typeType,
394+
Type: TypeType,
374395
Resolve: func(p ResolveParams) (interface{}, error) {
375396
if schema, ok := p.Source.(Schema); ok {
376397
if schema.MutationType() != nil {
@@ -383,7 +404,7 @@ func init() {
383404
"subscriptionType": &Field{
384405
Description: `If this server supports subscription, the type that ` +
385406
`subscription operations will be rooted at.`,
386-
Type: typeType,
407+
Type: TypeType,
387408
Resolve: func(p ResolveParams) (interface{}, error) {
388409
if schema, ok := p.Source.(Schema); ok {
389410
if schema.SubscriptionType() != nil {
@@ -396,7 +417,7 @@ func init() {
396417
"directives": &Field{
397418
Description: `A list of all directives supported by this server.`,
398419
Type: NewNonNull(NewList(
399-
NewNonNull(directiveType),
420+
NewNonNull(DirectiveType),
400421
)),
401422
Resolve: func(p ResolveParams) (interface{}, error) {
402423
if schema, ok := p.Source.(Schema); ok {
@@ -408,7 +429,7 @@ func init() {
408429
},
409430
})
410431

411-
enumValueType = NewObject(ObjectConfig{
432+
EnumValueType = NewObject(ObjectConfig{
412433
Name: "__EnumValue",
413434
Description: "One possible value for a given Enum. Enum values are unique values, not " +
414435
"a placeholder for a string or numeric value. However an Enum value is " +
@@ -437,8 +458,8 @@ func init() {
437458

438459
// Again, adding field configs to __Type that have cyclic reference here
439460
// because golang don't like them too much during init/compile-time
440-
typeType.AddFieldConfig("fields", &Field{
441-
Type: NewList(NewNonNull(fieldType)),
461+
TypeType.AddFieldConfig("fields", &Field{
462+
Type: NewList(NewNonNull(FieldType)),
442463
Args: FieldConfigArgument{
443464
"includeDeprecated": &ArgumentConfig{
444465
Type: Boolean,
@@ -476,8 +497,8 @@ func init() {
476497
return nil, nil
477498
},
478499
})
479-
typeType.AddFieldConfig("interfaces", &Field{
480-
Type: NewList(NewNonNull(typeType)),
500+
TypeType.AddFieldConfig("interfaces", &Field{
501+
Type: NewList(NewNonNull(TypeType)),
481502
Resolve: func(p ResolveParams) (interface{}, error) {
482503
switch ttype := p.Source.(type) {
483504
case *Object:
@@ -486,8 +507,8 @@ func init() {
486507
return nil, nil
487508
},
488509
})
489-
typeType.AddFieldConfig("possibleTypes", &Field{
490-
Type: NewList(NewNonNull(typeType)),
510+
TypeType.AddFieldConfig("possibleTypes", &Field{
511+
Type: NewList(NewNonNull(TypeType)),
491512
Resolve: func(p ResolveParams) (interface{}, error) {
492513
switch ttype := p.Source.(type) {
493514
case *Interface:
@@ -498,8 +519,8 @@ func init() {
498519
return nil, nil
499520
},
500521
})
501-
typeType.AddFieldConfig("enumValues", &Field{
502-
Type: NewList(NewNonNull(enumValueType)),
522+
TypeType.AddFieldConfig("enumValues", &Field{
523+
Type: NewList(NewNonNull(EnumValueType)),
503524
Args: FieldConfigArgument{
504525
"includeDeprecated": &ArgumentConfig{
505526
Type: Boolean,
@@ -525,8 +546,8 @@ func init() {
525546
return nil, nil
526547
},
527548
})
528-
typeType.AddFieldConfig("inputFields", &Field{
529-
Type: NewList(NewNonNull(inputValueType)),
549+
TypeType.AddFieldConfig("inputFields", &Field{
550+
Type: NewList(NewNonNull(InputValueType)),
530551
Resolve: func(p ResolveParams) (interface{}, error) {
531552
switch ttype := p.Source.(type) {
532553
case *InputObject:
@@ -539,15 +560,15 @@ func init() {
539560
return nil, nil
540561
},
541562
})
542-
typeType.AddFieldConfig("ofType", &Field{
543-
Type: typeType,
563+
TypeType.AddFieldConfig("ofType", &Field{
564+
Type: TypeType,
544565
})
545566

546567
// Note that these are FieldDefinition and not FieldConfig,
547-
// so the format for args is different. d
568+
// so the format for args is different.
548569
SchemaMetaFieldDef = &FieldDefinition{
549570
Name: "__schema",
550-
Type: NewNonNull(schemaType),
571+
Type: NewNonNull(SchemaType),
551572
Description: "Access the current type schema of this server.",
552573
Args: []*Argument{},
553574
Resolve: func(p ResolveParams) (interface{}, error) {
@@ -556,7 +577,7 @@ func init() {
556577
}
557578
TypeMetaFieldDef = &FieldDefinition{
558579
Name: "__type",
559-
Type: typeType,
580+
Type: TypeType,
560581
Description: "Request the type information of a single type.",
561582
Args: []*Argument{
562583
{

0 commit comments

Comments
 (0)