Skip to content

Commit 9cbbd65

Browse files
committed
RFC: Schema Language Directives (#376)
This implements adding directives to the experimental schema language by extending the *locations* a directive can be used. Notice that this provides no semantic meaning to these directives - they are purely a mechanism for annotating an AST - however future directives which contain semantic meaning may be introduced in the future (the first will be `@deprecated`). Commit: 1b6824bc5df15f8edb259d535aa41a81e2a07234 [1b6824b] Parents: 71b6a4aaec Author: Lee Byron <[email protected]> Date: 7 May 2016 at 5:56:25 AM SGT Labels: HEAD
1 parent e324096 commit 9cbbd65

12 files changed

+677
-130
lines changed

directives.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
package graphql
22

33
const (
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+
DirectiveLocationScalar = "SCALAR"
15+
DirectiveLocationObject = "OBJECT"
16+
DirectiveLocationFieldDefinition = "FIELD_DEFINITION"
17+
DirectiveLocationArgumentDefinition = "ARGUMENT_DEFINITION"
18+
DirectiveLocationInterface = "INTERFACE"
19+
DirectiveLocationUnion = "UNION"
20+
DirectiveLocationEnum = "ENUM"
21+
DirectiveLocationEnumValue = "ENUM_VALUE"
22+
DirectiveLocationInputObject = "INPUT_OBJECT"
23+
DirectiveLocationInputFieldDefinition = "INPUT_FIELD_DEFINITION"
1124
)
1225

1326
// Directive structs are used by the GraphQL runtime as a way of modifying execution

introspection.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,46 @@ func init() {
135135
Value: DirectiveLocationInlineFragment,
136136
Description: "Location adjacent to an inline fragment.",
137137
},
138+
"SCALAR": &EnumValueConfig{
139+
Value: DirectiveLocationScalar,
140+
Description: "Location adjacent to a scalar definition.",
141+
},
142+
"OBJECT": &EnumValueConfig{
143+
Value: DirectiveLocationObject,
144+
Description: "Location adjacent to a object definition.",
145+
},
146+
"FIELD_DEFINITION": &EnumValueConfig{
147+
Value: DirectiveLocationFieldDefinition,
148+
Description: "Location adjacent to a field definition.",
149+
},
150+
"ARGUMENT_DEFINITION": &EnumValueConfig{
151+
Value: DirectiveLocationArgumentDefinition,
152+
Description: "Location adjacent to an argument definition.",
153+
},
154+
"INTERFACE": &EnumValueConfig{
155+
Value: DirectiveLocationInterface,
156+
Description: "Location adjacent to an interface definition.",
157+
},
158+
"UNION": &EnumValueConfig{
159+
Value: DirectiveLocationUnion,
160+
Description: "Location adjacent to a union definition.",
161+
},
162+
"ENUM": &EnumValueConfig{
163+
Value: DirectiveLocationEnum,
164+
Description: "Location adjacent to an enum definition.",
165+
},
166+
"ENUM_VALUE": &EnumValueConfig{
167+
Value: DirectiveLocationEnumValue,
168+
Description: "Location adjacent to an enum value definition.",
169+
},
170+
"INPUT_OBJECT": &EnumValueConfig{
171+
Value: DirectiveLocationInputObject,
172+
Description: "Location adjacent to an input object type definition.",
173+
},
174+
"INPUT_FIELD_DEFINITION": &EnumValueConfig{
175+
Value: DirectiveLocationInputFieldDefinition,
176+
Description: "Location adjacent to an input object field definition.",
177+
},
138178
},
139179
})
140180

language/ast/type_definitions.go

Lines changed: 72 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,21 @@ func (def *OperationTypeDefinition) GetLoc() *Location {
100100

101101
// ScalarDefinition implements Node, Definition
102102
type ScalarDefinition struct {
103-
Kind string
104-
Loc *Location
105-
Name *Name
103+
Kind string
104+
Loc *Location
105+
Name *Name
106+
Directives []*Directive
106107
}
107108

108109
func NewScalarDefinition(def *ScalarDefinition) *ScalarDefinition {
109110
if def == nil {
110111
def = &ScalarDefinition{}
111112
}
112113
return &ScalarDefinition{
113-
Kind: kinds.ScalarDefinition,
114-
Loc: def.Loc,
115-
Name: def.Name,
114+
Kind: kinds.ScalarDefinition,
115+
Loc: def.Loc,
116+
Name: def.Name,
117+
Directives: def.Directives,
116118
}
117119
}
118120

@@ -146,6 +148,7 @@ type ObjectDefinition struct {
146148
Loc *Location
147149
Name *Name
148150
Interfaces []*Named
151+
Directives []*Directive
149152
Fields []*FieldDefinition
150153
}
151154

@@ -158,6 +161,7 @@ func NewObjectDefinition(def *ObjectDefinition) *ObjectDefinition {
158161
Loc: def.Loc,
159162
Name: def.Name,
160163
Interfaces: def.Interfaces,
164+
Directives: def.Directives,
161165
Fields: def.Fields,
162166
}
163167
}
@@ -188,23 +192,25 @@ func (def *ObjectDefinition) GetOperation() string {
188192

189193
// FieldDefinition implements Node
190194
type FieldDefinition struct {
191-
Kind string
192-
Loc *Location
193-
Name *Name
194-
Arguments []*InputValueDefinition
195-
Type Type
195+
Kind string
196+
Loc *Location
197+
Name *Name
198+
Arguments []*InputValueDefinition
199+
Type Type
200+
Directives []*Directive
196201
}
197202

198203
func NewFieldDefinition(def *FieldDefinition) *FieldDefinition {
199204
if def == nil {
200205
def = &FieldDefinition{}
201206
}
202207
return &FieldDefinition{
203-
Kind: kinds.FieldDefinition,
204-
Loc: def.Loc,
205-
Name: def.Name,
206-
Arguments: def.Arguments,
207-
Type: def.Type,
208+
Kind: kinds.FieldDefinition,
209+
Loc: def.Loc,
210+
Name: def.Name,
211+
Arguments: def.Arguments,
212+
Type: def.Type,
213+
Directives: def.Directives,
208214
}
209215
}
210216

@@ -223,6 +229,7 @@ type InputValueDefinition struct {
223229
Name *Name
224230
Type Type
225231
DefaultValue Value
232+
Directives []*Directive
226233
}
227234

228235
func NewInputValueDefinition(def *InputValueDefinition) *InputValueDefinition {
@@ -235,6 +242,7 @@ func NewInputValueDefinition(def *InputValueDefinition) *InputValueDefinition {
235242
Name: def.Name,
236243
Type: def.Type,
237244
DefaultValue: def.DefaultValue,
245+
Directives: def.Directives,
238246
}
239247
}
240248

@@ -248,21 +256,23 @@ func (def *InputValueDefinition) GetLoc() *Location {
248256

249257
// InterfaceDefinition implements Node, Definition
250258
type InterfaceDefinition struct {
251-
Kind string
252-
Loc *Location
253-
Name *Name
254-
Fields []*FieldDefinition
259+
Kind string
260+
Loc *Location
261+
Name *Name
262+
Directives []*Directive
263+
Fields []*FieldDefinition
255264
}
256265

257266
func NewInterfaceDefinition(def *InterfaceDefinition) *InterfaceDefinition {
258267
if def == nil {
259268
def = &InterfaceDefinition{}
260269
}
261270
return &InterfaceDefinition{
262-
Kind: kinds.InterfaceDefinition,
263-
Loc: def.Loc,
264-
Name: def.Name,
265-
Fields: def.Fields,
271+
Kind: kinds.InterfaceDefinition,
272+
Loc: def.Loc,
273+
Name: def.Name,
274+
Directives: def.Directives,
275+
Fields: def.Fields,
266276
}
267277
}
268278

@@ -292,21 +302,23 @@ func (def *InterfaceDefinition) GetOperation() string {
292302

293303
// UnionDefinition implements Node, Definition
294304
type UnionDefinition struct {
295-
Kind string
296-
Loc *Location
297-
Name *Name
298-
Types []*Named
305+
Kind string
306+
Loc *Location
307+
Name *Name
308+
Directives []*Directive
309+
Types []*Named
299310
}
300311

301312
func NewUnionDefinition(def *UnionDefinition) *UnionDefinition {
302313
if def == nil {
303314
def = &UnionDefinition{}
304315
}
305316
return &UnionDefinition{
306-
Kind: kinds.UnionDefinition,
307-
Loc: def.Loc,
308-
Name: def.Name,
309-
Types: def.Types,
317+
Kind: kinds.UnionDefinition,
318+
Loc: def.Loc,
319+
Name: def.Name,
320+
Directives: def.Directives,
321+
Types: def.Types,
310322
}
311323
}
312324

@@ -336,21 +348,23 @@ func (def *UnionDefinition) GetOperation() string {
336348

337349
// EnumDefinition implements Node, Definition
338350
type EnumDefinition struct {
339-
Kind string
340-
Loc *Location
341-
Name *Name
342-
Values []*EnumValueDefinition
351+
Kind string
352+
Loc *Location
353+
Name *Name
354+
Directives []*Directive
355+
Values []*EnumValueDefinition
343356
}
344357

345358
func NewEnumDefinition(def *EnumDefinition) *EnumDefinition {
346359
if def == nil {
347360
def = &EnumDefinition{}
348361
}
349362
return &EnumDefinition{
350-
Kind: kinds.EnumDefinition,
351-
Loc: def.Loc,
352-
Name: def.Name,
353-
Values: def.Values,
363+
Kind: kinds.EnumDefinition,
364+
Loc: def.Loc,
365+
Name: def.Name,
366+
Directives: def.Directives,
367+
Values: def.Values,
354368
}
355369
}
356370

@@ -380,19 +394,21 @@ func (def *EnumDefinition) GetOperation() string {
380394

381395
// EnumValueDefinition implements Node, Definition
382396
type EnumValueDefinition struct {
383-
Kind string
384-
Loc *Location
385-
Name *Name
397+
Kind string
398+
Loc *Location
399+
Name *Name
400+
Directives []*Directive
386401
}
387402

388403
func NewEnumValueDefinition(def *EnumValueDefinition) *EnumValueDefinition {
389404
if def == nil {
390405
def = &EnumValueDefinition{}
391406
}
392407
return &EnumValueDefinition{
393-
Kind: kinds.EnumValueDefinition,
394-
Loc: def.Loc,
395-
Name: def.Name,
408+
Kind: kinds.EnumValueDefinition,
409+
Loc: def.Loc,
410+
Name: def.Name,
411+
Directives: def.Directives,
396412
}
397413
}
398414

@@ -406,21 +422,23 @@ func (def *EnumValueDefinition) GetLoc() *Location {
406422

407423
// InputObjectDefinition implements Node, Definition
408424
type InputObjectDefinition struct {
409-
Kind string
410-
Loc *Location
411-
Name *Name
412-
Fields []*InputValueDefinition
425+
Kind string
426+
Loc *Location
427+
Name *Name
428+
Directives []*Directive
429+
Fields []*InputValueDefinition
413430
}
414431

415432
func NewInputObjectDefinition(def *InputObjectDefinition) *InputObjectDefinition {
416433
if def == nil {
417434
def = &InputObjectDefinition{}
418435
}
419436
return &InputObjectDefinition{
420-
Kind: kinds.InputObjectDefinition,
421-
Loc: def.Loc,
422-
Name: def.Name,
423-
Fields: def.Fields,
437+
Kind: kinds.InputObjectDefinition,
438+
Loc: def.Loc,
439+
Name: def.Name,
440+
Directives: def.Directives,
441+
Fields: def.Fields,
424442
}
425443
}
426444

0 commit comments

Comments
 (0)