1// introspection implements the spec defined in https://github.com/facebook/graphql/blob/master/spec/Section%204%20--%20Introspection.md#schema-introspection
2package introspection
3
4import "github.com/vektah/gqlparser/ast"
5
6type (
7 Directive struct {
8 Name string
9 Description string
10 Locations []string
11 Args []InputValue
12 }
13
14 EnumValue struct {
15 Name string
16 Description string
17 IsDeprecated bool
18 DeprecationReason string
19 }
20
21 Field struct {
22 Name string
23 Description string
24 Type *Type
25 Args []InputValue
26 IsDeprecated bool
27 DeprecationReason string
28 }
29
30 InputValue struct {
31 Name string
32 Description string
33 DefaultValue *string
34 Type *Type
35 }
36)
37
38func WrapSchema(schema *ast.Schema) *Schema {
39 return &Schema{schema: schema}
40}
41
42func isDeprecated(directives ast.DirectiveList) bool {
43 return directives.ForName("deprecated") != nil
44}
45
46func deprecationReason(directives ast.DirectiveList) string {
47 deprecation := directives.ForName("deprecated")
48 if deprecation == nil {
49 return ""
50 }
51
52 reason := deprecation.Arguments.ForName("reason")
53 if reason == nil {
54 return ""
55 }
56
57 return reason.Value.Raw
58}