1
1
package graphql
2
2
3
3
const (
4
+ // Operations
4
5
DirectiveLocationQuery = "QUERY"
5
6
DirectiveLocationMutation = "MUTATION"
6
7
DirectiveLocationSubscription = "SUBSCRIPTION"
7
8
DirectiveLocationField = "FIELD"
8
9
DirectiveLocationFragmentDefinition = "FRAGMENT_DEFINITION"
9
10
DirectiveLocationFragmentSpread = "FRAGMENT_SPREAD"
10
11
DirectiveLocationInlineFragment = "INLINE_FRAGMENT"
12
+
13
+ // Schema Definitions
14
+ DirectiveLocationSchema = "SCHEMA"
15
+ DirectiveLocationScalar = "SCALAR"
16
+ DirectiveLocationObject = "OBJECT"
17
+ DirectiveLocationFieldDefinition = "FIELD_DEFINITION"
18
+ DirectiveLocationArgumentDefinition = "ARGUMENT_DEFINITION"
19
+ DirectiveLocationInterface = "INTERFACE"
20
+ DirectiveLocationUnion = "UNION"
21
+ DirectiveLocationEnum = "ENUM"
22
+ DirectiveLocationEnumValue = "ENUM_VALUE"
23
+ DirectiveLocationInputObject = "INPUT_OBJECT"
24
+ DirectiveLocationInputFieldDefinition = "INPUT_FIELD_DEFINITION"
11
25
)
12
26
27
+ // DefaultDeprecationReason Constant string used for default reason for a deprecation.
28
+ const DefaultDeprecationReason = "No longer supported"
29
+
30
+ // SpecifiedRules The full list of specified directives.
31
+ var SpecifiedDirectives = []* Directive {
32
+ IncludeDirective ,
33
+ SkipDirective ,
34
+ DeprecatedDirective ,
35
+ }
36
+
13
37
// Directive structs are used by the GraphQL runtime as a way of modifying execution
14
38
// behavior. Type system creators will usually not create these directly.
15
39
type Directive struct {
@@ -76,7 +100,7 @@ func NewDirective(config DirectiveConfig) *Directive {
76
100
return dir
77
101
}
78
102
79
- // IncludeDirective is used to conditionally include fields or fragments
103
+ // IncludeDirective is used to conditionally include fields or fragments.
80
104
var IncludeDirective = NewDirective (DirectiveConfig {
81
105
Name : "include" ,
82
106
Description : "Directs the executor to include this field or fragment only when " +
@@ -94,7 +118,7 @@ var IncludeDirective = NewDirective(DirectiveConfig{
94
118
},
95
119
})
96
120
97
- // SkipDirective Used to conditionally skip (exclude) fields or fragments
121
+ // SkipDirective Used to conditionally skip (exclude) fields or fragments.
98
122
var SkipDirective = NewDirective (DirectiveConfig {
99
123
Name : "skip" ,
100
124
Description : "Directs the executor to skip this field or fragment when the `if` " +
@@ -111,3 +135,22 @@ var SkipDirective = NewDirective(DirectiveConfig{
111
135
DirectiveLocationInlineFragment ,
112
136
},
113
137
})
138
+
139
+ // DeprecatedDirective Used to declare element of a GraphQL schema as deprecated.
140
+ var DeprecatedDirective = NewDirective (DirectiveConfig {
141
+ Name : "deprecated" ,
142
+ Description : "Marks an element of a GraphQL schema as no longer supported." ,
143
+ Args : FieldConfigArgument {
144
+ "reason" : & ArgumentConfig {
145
+ Type : String ,
146
+ Description : "Explains why this element was deprecated, usually also including a " +
147
+ "suggestion for how to access supported similar data. Formatted" +
148
+ "in [Markdown](https://daringfireball.net/projects/markdown/)." ,
149
+ DefaultValue : DefaultDeprecationReason ,
150
+ },
151
+ },
152
+ Locations : []string {
153
+ DirectiveLocationFieldDefinition ,
154
+ DirectiveLocationEnumValue ,
155
+ },
156
+ })
0 commit comments