Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from Code-Hex/add/variable-definition
Browse files Browse the repository at this point in the history
add variable definition
  • Loading branch information
Code-Hex authored Apr 3, 2021
2 parents a064739 + c3be47b commit 9fa923b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions ast/directive.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
LocationFragmentDefinition DirectiveLocation = `FRAGMENT_DEFINITION`
LocationFragmentSpread DirectiveLocation = `FRAGMENT_SPREAD`
LocationInlineFragment DirectiveLocation = `INLINE_FRAGMENT`
LocationVariableDefinition DirectiveLocation = `VARIABLE_DEFINITION`

// Type System
LocationSchema DirectiveLocation = `SCHEMA`
Expand Down
8 changes: 7 additions & 1 deletion parser/query_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ variables:
locations: [{ line: 1, column: 37 }]

- name: can have directives
input: 'query ($withDirective: String @first @second, $withoutDirective: String) { f }'
input: 'query ($withDirective: String @first @second @third(if: true), $withoutDirective: String) { f }'
ast: |
<QueryDocument>
Operations: [OperationDefinition]
Expand All @@ -57,6 +57,12 @@ variables:
Name: "first"
- <Directive>
Name: "second"
- <Directive>
Name: "third"
Arguments: [Argument]
- <Argument>
Name: "if"
Value: true
- <VariableDefinition>
Variable: "withoutDirective"
Type: String
Expand Down
2 changes: 2 additions & 0 deletions parser/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ func (p *parser) parseDirectiveLocation() DirectiveLocation {
return LocationFragmentSpread
case `INLINE_FRAGMENT`:
return LocationInlineFragment
case `VARIABLE_DEFINITION`:
return LocationVariableDefinition
case `SCHEMA`:
return LocationSchema
case `SCALAR`:
Expand Down
54 changes: 54 additions & 0 deletions parser/schema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,60 @@ directives:
- DirectiveLocation("FIELD")
IsRepeatable: false
- name: executable
input: |
directive @onQuery on QUERY
directive @onMutation on MUTATION
directive @onSubscription on SUBSCRIPTION
directive @onField on FIELD
directive @onFragmentDefinition on FRAGMENT_DEFINITION
directive @onFragmentSpread on FRAGMENT_SPREAD
directive @onInlineFragment on INLINE_FRAGMENT
directive @onVariableDefinition on VARIABLE_DEFINITION
ast: |
<SchemaDocument>
Directives: [DirectiveDefinition]
- <DirectiveDefinition>
Name: "onQuery"
Locations: [DirectiveLocation]
- DirectiveLocation("QUERY")
IsRepeatable: false
- <DirectiveDefinition>
Name: "onMutation"
Locations: [DirectiveLocation]
- DirectiveLocation("MUTATION")
IsRepeatable: false
- <DirectiveDefinition>
Name: "onSubscription"
Locations: [DirectiveLocation]
- DirectiveLocation("SUBSCRIPTION")
IsRepeatable: false
- <DirectiveDefinition>
Name: "onField"
Locations: [DirectiveLocation]
- DirectiveLocation("FIELD")
IsRepeatable: false
- <DirectiveDefinition>
Name: "onFragmentDefinition"
Locations: [DirectiveLocation]
- DirectiveLocation("FRAGMENT_DEFINITION")
IsRepeatable: false
- <DirectiveDefinition>
Name: "onFragmentSpread"
Locations: [DirectiveLocation]
- DirectiveLocation("FRAGMENT_SPREAD")
IsRepeatable: false
- <DirectiveDefinition>
Name: "onInlineFragment"
Locations: [DirectiveLocation]
- DirectiveLocation("INLINE_FRAGMENT")
IsRepeatable: false
- <DirectiveDefinition>
Name: "onVariableDefinition"
Locations: [DirectiveLocation]
- DirectiveLocation("VARIABLE_DEFINITION")
IsRepeatable: false
- name: repeatable
input: directive @foo repeatable on FIELD
ast: |
Expand Down
1 change: 1 addition & 0 deletions validator/prelude.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ enum __DirectiveLocation {
FRAGMENT_DEFINITION
FRAGMENT_SPREAD
INLINE_FRAGMENT
VARIABLE_DEFINITION
SCHEMA
SCALAR
OBJECT
Expand Down

0 comments on commit 9fa923b

Please sign in to comment.