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 deprecation *ast.Directive
18 }
19
20 Field struct {
21 Name string
22 Description string
23 Type *Type
24 Args []InputValue
25 deprecation *ast.Directive
26 }
27
28 InputValue struct {
29 Name string
30 Description string
31 DefaultValue *string
32 Type *Type
33 }
34)
35
36func WrapSchema(schema *ast.Schema) *Schema {
37 return &Schema{schema: schema}
38}
39
40func (f *EnumValue) IsDeprecated() bool {
41 return f.deprecation != nil
42}
43
44func (f *EnumValue) DeprecationReason() *string {
45 if f.deprecation == nil {
46 return nil
47 }
48
49 reason := f.deprecation.Arguments.ForName("reason")
50 if reason == nil {
51 return nil
52 }
53
54 return &reason.Value.Raw
55}
56
57func (f *Field) IsDeprecated() bool {
58 return f.deprecation != nil
59}
60
61func (f *Field) DeprecationReason() *string {
62 if f.deprecation == nil {
63 return nil
64 }
65
66 reason := f.deprecation.Arguments.ForName("reason")
67 if reason == nil {
68 return nil
69 }
70
71 return &reason.Value.Raw
72}