...
1
2 package introspection
3
4 import "github.com/vektah/gqlparser/v2/ast"
5
6 type (
7 Directive struct {
8 Name string
9 description string
10 Locations []string
11 Args []InputValue
12 IsRepeatable bool
13 }
14
15 EnumValue struct {
16 Name string
17 description string
18 deprecation *ast.Directive
19 }
20
21 Field struct {
22 Name string
23 description string
24 Type *Type
25 Args []InputValue
26 deprecation *ast.Directive
27 }
28
29 InputValue struct {
30 Name string
31 description string
32 DefaultValue *string
33 Type *Type
34 }
35 )
36
37 func WrapSchema(schema *ast.Schema) *Schema {
38 return &Schema{schema: schema}
39 }
40
41 func (f *EnumValue) Description() *string {
42 if f.description == "" {
43 return nil
44 }
45 return &f.description
46 }
47
48 func (f *EnumValue) IsDeprecated() bool {
49 return f.deprecation != nil
50 }
51
52 func (f *EnumValue) DeprecationReason() *string {
53 if f.deprecation == nil {
54 return nil
55 }
56
57 reason := f.deprecation.Arguments.ForName("reason")
58 if reason == nil {
59 return nil
60 }
61
62 return &reason.Value.Raw
63 }
64
65 func (f *Field) Description() *string {
66 if f.description == "" {
67 return nil
68 }
69 return &f.description
70 }
71
72 func (f *Field) IsDeprecated() bool {
73 return f.deprecation != nil
74 }
75
76 func (f *Field) DeprecationReason() *string {
77 if f.deprecation == nil || !f.IsDeprecated() {
78 return nil
79 }
80
81 reason := f.deprecation.Arguments.ForName("reason")
82
83 if reason == nil {
84 defaultReason := "No longer supported"
85 return &defaultReason
86 }
87
88 return &reason.Value.Raw
89 }
90
91 func (f *InputValue) Description() *string {
92 if f.description == "" {
93 return nil
94 }
95 return &f.description
96 }
97
98 func (f *Directive) Description() *string {
99 if f.description == "" {
100 return nil
101 }
102 return &f.description
103 }
104
View as plain text