11package graphql
22
33const (
4+ // Operations
45 DirectiveLocationQuery = "QUERY"
56 DirectiveLocationMutation = "MUTATION"
67 DirectiveLocationSubscription = "SUBSCRIPTION"
78 DirectiveLocationField = "FIELD"
89 DirectiveLocationFragmentDefinition = "FRAGMENT_DEFINITION"
910 DirectiveLocationFragmentSpread = "FRAGMENT_SPREAD"
1011 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"
1125)
1226
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+
1337// Directive structs are used by the GraphQL runtime as a way of modifying execution
1438// behavior. Type system creators will usually not create these directly.
1539type Directive struct {
@@ -76,7 +100,7 @@ func NewDirective(config DirectiveConfig) *Directive {
76100 return dir
77101}
78102
79- // IncludeDirective is used to conditionally include fields or fragments
103+ // IncludeDirective is used to conditionally include fields or fragments.
80104var IncludeDirective = NewDirective (DirectiveConfig {
81105 Name : "include" ,
82106 Description : "Directs the executor to include this field or fragment only when " +
@@ -94,7 +118,7 @@ var IncludeDirective = NewDirective(DirectiveConfig{
94118 },
95119})
96120
97- // SkipDirective Used to conditionally skip (exclude) fields or fragments
121+ // SkipDirective Used to conditionally skip (exclude) fields or fragments.
98122var SkipDirective = NewDirective (DirectiveConfig {
99123 Name : "skip" ,
100124 Description : "Directs the executor to skip this field or fragment when the `if` " +
@@ -111,3 +135,22 @@ var SkipDirective = NewDirective(DirectiveConfig{
111135 DirectiveLocationInlineFragment ,
112136 },
113137})
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