Skip to content

Commit

Permalink
allow directives on variable definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
vikstrous committed Oct 22, 2020
1 parent 83ee611 commit 9914f67
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions ast/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type VariableDefinition struct {
Variable string
Type *Type
DefaultValue *Value
Directives DirectiveList
Position *Position `dump:"-"`

// Requires validation
Expand Down
2 changes: 2 additions & 0 deletions parser/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func (p *parser) parseVariableDefinition() *VariableDefinition {
def.DefaultValue = p.parseValueLiteral(true)
}

def.Directives = p.parseDirectives(false)

return &def
}

Expand Down
24 changes: 24 additions & 0 deletions parser/query_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ variables:
message: 'Unexpected $'
locations: [{ line: 1, column: 37 }]

- name: can have directives
input: 'query ($withDirective: String @first @second, $withoutDirective: String) { f }'
ast: |
<QueryDocument>
Operations: [OperationDefinition]
- <OperationDefinition>
Operation: Operation("query")
VariableDefinitions: [VariableDefinition]
- <VariableDefinition>
Variable: "withDirective"
Type: String
Directives: [Directive]
- <Directive>
Name: "first"
- <Directive>
Name: "second"
- <VariableDefinition>
Variable: "withoutDirective"
Type: String
SelectionSet: [Selection]
- <Field>
Alias: "f"
Name: "f"
fragments:
- name: can not be named 'on'
input: 'fragment on on on { on }'
Expand Down

0 comments on commit 9914f67

Please sign in to comment.