Skip to content

Commit

Permalink
RFC: Schema Language Directives (#376)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sogko committed Jun 7, 2016
1 parent e324096 commit 9cbbd65
Show file tree
Hide file tree
Showing 12 changed files with 677 additions and 130 deletions.
13 changes: 13 additions & 0 deletions directives.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package graphql

const (
// Operations
DirectiveLocationQuery = "QUERY"
DirectiveLocationMutation = "MUTATION"
DirectiveLocationSubscription = "SUBSCRIPTION"
DirectiveLocationField = "FIELD"
DirectiveLocationFragmentDefinition = "FRAGMENT_DEFINITION"
DirectiveLocationFragmentSpread = "FRAGMENT_SPREAD"
DirectiveLocationInlineFragment = "INLINE_FRAGMENT"

// Schema Definitions
DirectiveLocationScalar = "SCALAR"
DirectiveLocationObject = "OBJECT"
DirectiveLocationFieldDefinition = "FIELD_DEFINITION"
DirectiveLocationArgumentDefinition = "ARGUMENT_DEFINITION"
DirectiveLocationInterface = "INTERFACE"
DirectiveLocationUnion = "UNION"
DirectiveLocationEnum = "ENUM"
DirectiveLocationEnumValue = "ENUM_VALUE"
DirectiveLocationInputObject = "INPUT_OBJECT"
DirectiveLocationInputFieldDefinition = "INPUT_FIELD_DEFINITION"
)

// Directive structs are used by the GraphQL runtime as a way of modifying execution
Expand Down
40 changes: 40 additions & 0 deletions introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,46 @@ func init() {
Value: DirectiveLocationInlineFragment,
Description: "Location adjacent to an inline fragment.",
},
"SCALAR": &EnumValueConfig{
Value: DirectiveLocationScalar,
Description: "Location adjacent to a scalar definition.",
},
"OBJECT": &EnumValueConfig{
Value: DirectiveLocationObject,
Description: "Location adjacent to a object definition.",
},
"FIELD_DEFINITION": &EnumValueConfig{
Value: DirectiveLocationFieldDefinition,
Description: "Location adjacent to a field definition.",
},
"ARGUMENT_DEFINITION": &EnumValueConfig{
Value: DirectiveLocationArgumentDefinition,
Description: "Location adjacent to an argument definition.",
},
"INTERFACE": &EnumValueConfig{
Value: DirectiveLocationInterface,
Description: "Location adjacent to an interface definition.",
},
"UNION": &EnumValueConfig{
Value: DirectiveLocationUnion,
Description: "Location adjacent to a union definition.",
},
"ENUM": &EnumValueConfig{
Value: DirectiveLocationEnum,
Description: "Location adjacent to an enum definition.",
},
"ENUM_VALUE": &EnumValueConfig{
Value: DirectiveLocationEnumValue,
Description: "Location adjacent to an enum value definition.",
},
"INPUT_OBJECT": &EnumValueConfig{
Value: DirectiveLocationInputObject,
Description: "Location adjacent to an input object type definition.",
},
"INPUT_FIELD_DEFINITION": &EnumValueConfig{
Value: DirectiveLocationInputFieldDefinition,
Description: "Location adjacent to an input object field definition.",
},
},
})

Expand Down
126 changes: 72 additions & 54 deletions language/ast/type_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,21 @@ func (def *OperationTypeDefinition) GetLoc() *Location {

// ScalarDefinition implements Node, Definition
type ScalarDefinition struct {
Kind string
Loc *Location
Name *Name
Kind string
Loc *Location
Name *Name
Directives []*Directive
}

func NewScalarDefinition(def *ScalarDefinition) *ScalarDefinition {
if def == nil {
def = &ScalarDefinition{}
}
return &ScalarDefinition{
Kind: kinds.ScalarDefinition,
Loc: def.Loc,
Name: def.Name,
Kind: kinds.ScalarDefinition,
Loc: def.Loc,
Name: def.Name,
Directives: def.Directives,
}
}

Expand Down Expand Up @@ -146,6 +148,7 @@ type ObjectDefinition struct {
Loc *Location
Name *Name
Interfaces []*Named
Directives []*Directive
Fields []*FieldDefinition
}

Expand All @@ -158,6 +161,7 @@ func NewObjectDefinition(def *ObjectDefinition) *ObjectDefinition {
Loc: def.Loc,
Name: def.Name,
Interfaces: def.Interfaces,
Directives: def.Directives,
Fields: def.Fields,
}
}
Expand Down Expand Up @@ -188,23 +192,25 @@ func (def *ObjectDefinition) GetOperation() string {

// FieldDefinition implements Node
type FieldDefinition struct {
Kind string
Loc *Location
Name *Name
Arguments []*InputValueDefinition
Type Type
Kind string
Loc *Location
Name *Name
Arguments []*InputValueDefinition
Type Type
Directives []*Directive
}

func NewFieldDefinition(def *FieldDefinition) *FieldDefinition {
if def == nil {
def = &FieldDefinition{}
}
return &FieldDefinition{
Kind: kinds.FieldDefinition,
Loc: def.Loc,
Name: def.Name,
Arguments: def.Arguments,
Type: def.Type,
Kind: kinds.FieldDefinition,
Loc: def.Loc,
Name: def.Name,
Arguments: def.Arguments,
Type: def.Type,
Directives: def.Directives,
}
}

Expand All @@ -223,6 +229,7 @@ type InputValueDefinition struct {
Name *Name
Type Type
DefaultValue Value
Directives []*Directive
}

func NewInputValueDefinition(def *InputValueDefinition) *InputValueDefinition {
Expand All @@ -235,6 +242,7 @@ func NewInputValueDefinition(def *InputValueDefinition) *InputValueDefinition {
Name: def.Name,
Type: def.Type,
DefaultValue: def.DefaultValue,
Directives: def.Directives,
}
}

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

// InterfaceDefinition implements Node, Definition
type InterfaceDefinition struct {
Kind string
Loc *Location
Name *Name
Fields []*FieldDefinition
Kind string
Loc *Location
Name *Name
Directives []*Directive
Fields []*FieldDefinition
}

func NewInterfaceDefinition(def *InterfaceDefinition) *InterfaceDefinition {
if def == nil {
def = &InterfaceDefinition{}
}
return &InterfaceDefinition{
Kind: kinds.InterfaceDefinition,
Loc: def.Loc,
Name: def.Name,
Fields: def.Fields,
Kind: kinds.InterfaceDefinition,
Loc: def.Loc,
Name: def.Name,
Directives: def.Directives,
Fields: def.Fields,
}
}

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

// UnionDefinition implements Node, Definition
type UnionDefinition struct {
Kind string
Loc *Location
Name *Name
Types []*Named
Kind string
Loc *Location
Name *Name
Directives []*Directive
Types []*Named
}

func NewUnionDefinition(def *UnionDefinition) *UnionDefinition {
if def == nil {
def = &UnionDefinition{}
}
return &UnionDefinition{
Kind: kinds.UnionDefinition,
Loc: def.Loc,
Name: def.Name,
Types: def.Types,
Kind: kinds.UnionDefinition,
Loc: def.Loc,
Name: def.Name,
Directives: def.Directives,
Types: def.Types,
}
}

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

// EnumDefinition implements Node, Definition
type EnumDefinition struct {
Kind string
Loc *Location
Name *Name
Values []*EnumValueDefinition
Kind string
Loc *Location
Name *Name
Directives []*Directive
Values []*EnumValueDefinition
}

func NewEnumDefinition(def *EnumDefinition) *EnumDefinition {
if def == nil {
def = &EnumDefinition{}
}
return &EnumDefinition{
Kind: kinds.EnumDefinition,
Loc: def.Loc,
Name: def.Name,
Values: def.Values,
Kind: kinds.EnumDefinition,
Loc: def.Loc,
Name: def.Name,
Directives: def.Directives,
Values: def.Values,
}
}

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

// EnumValueDefinition implements Node, Definition
type EnumValueDefinition struct {
Kind string
Loc *Location
Name *Name
Kind string
Loc *Location
Name *Name
Directives []*Directive
}

func NewEnumValueDefinition(def *EnumValueDefinition) *EnumValueDefinition {
if def == nil {
def = &EnumValueDefinition{}
}
return &EnumValueDefinition{
Kind: kinds.EnumValueDefinition,
Loc: def.Loc,
Name: def.Name,
Kind: kinds.EnumValueDefinition,
Loc: def.Loc,
Name: def.Name,
Directives: def.Directives,
}
}

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

// InputObjectDefinition implements Node, Definition
type InputObjectDefinition struct {
Kind string
Loc *Location
Name *Name
Fields []*InputValueDefinition
Kind string
Loc *Location
Name *Name
Directives []*Directive
Fields []*InputValueDefinition
}

func NewInputObjectDefinition(def *InputObjectDefinition) *InputObjectDefinition {
if def == nil {
def = &InputObjectDefinition{}
}
return &InputObjectDefinition{
Kind: kinds.InputObjectDefinition,
Loc: def.Loc,
Name: def.Name,
Fields: def.Fields,
Kind: kinds.InputObjectDefinition,
Loc: def.Loc,
Name: def.Name,
Directives: def.Directives,
Fields: def.Fields,
}
}

Expand Down
Loading

0 comments on commit 9cbbd65

Please sign in to comment.