Skip to content

Commit 2aed570

Browse files
Allow directives on variable variable_definition_test (#1028)
See graphql/graphql-spec#510 Adds support for directives on variable definitions in the parser.
1 parent 5e54c50 commit 2aed570

File tree

5 files changed

+8
-2
lines changed

5 files changed

+8
-2
lines changed

lib/absinthe/blueprint/document/variable_definition.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ defmodule Absinthe.Blueprint.Document.VariableDefinition do
77
defstruct [
88
:name,
99
:type,
10+
directives: [],
1011
default_value: nil,
1112
source_location: nil,
1213
# Added by phases
@@ -19,6 +20,7 @@ defmodule Absinthe.Blueprint.Document.VariableDefinition do
1920
@type t :: %__MODULE__{
2021
name: String.t(),
2122
type: Blueprint.TypeReference.t(),
23+
directives: [Blueprint.Directive.t()],
2224
default_value: Blueprint.Input.t(),
2325
source_location: nil | Blueprint.SourceLocation.t(),
2426
provided_value: nil | Blueprint.Input.t(),

lib/absinthe/blueprint/transform.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ defmodule Absinthe.Blueprint.Transform do
7070
Blueprint.Document.Fragment.Inline => [:selections, :directives],
7171
Blueprint.Document.Fragment.Named => [:selections, :directives],
7272
Blueprint.Document.Fragment.Spread => [:directives],
73-
Blueprint.Document.VariableDefinition => [:type, :default_value],
73+
Blueprint.Document.VariableDefinition => [:type, :default_value, :directives],
7474
Blueprint.Input.Argument => [:input_value],
7575
Blueprint.Input.Field => [:input_value],
7676
Blueprint.Input.Object => [:fields],

lib/absinthe/language/variable_definition.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule Absinthe.Language.VariableDefinition do
55

66
defstruct variable: nil,
77
type: nil,
8+
directives: [],
89
default_value: nil,
910
loc: %{line: nil}
1011

@@ -20,6 +21,7 @@ defmodule Absinthe.Language.VariableDefinition do
2021
%Blueprint.Document.VariableDefinition{
2122
name: node.variable.name,
2223
type: Blueprint.Draft.convert(node.type, doc),
24+
directives: Absinthe.Blueprint.Draft.convert(node.directives, doc),
2325
default_value: Blueprint.Draft.convert(node.default_value, doc),
2426
source_location: source_location(node)
2527
}

src/absinthe_parser.yrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ VariableDefinitionList -> VariableDefinition : ['$1'].
5555
VariableDefinitionList -> VariableDefinition VariableDefinitionList : ['$1'|'$2'].
5656
VariableDefinition -> Variable ':' Type : build_ast_node('VariableDefinition', #{'variable' => '$1', 'type' => '$3'}, extract_child_location('$1')).
5757
VariableDefinition -> Variable ':' Type DefaultValue : build_ast_node('VariableDefinition', #{'variable' => '$1', 'type' => '$3', 'default_value' => '$4'}, extract_child_location('$1')).
58+
VariableDefinition -> Variable ':' Type DefaultValue Directives : build_ast_node('VariableDefinition', #{'variable' => '$1', 'type' => '$3', 'default_value' => '$4', 'directives' => '$5'}, extract_child_location('$1')).
5859
Variable -> '$' NameWithoutOn : build_ast_node('Variable', #{'name' => extract_binary('$2')}, extract_location('$1')).
5960
Variable -> '$' 'on' : build_ast_node('Variable', #{'name' => extract_binary('$2')}, extract_location('$1')).
6061

test/absinthe/language/variable_definition_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Absinthe.Language.VariableDefinitionTest do
44
alias Absinthe.{Blueprint, Language}
55

66
@query """
7-
query Foo($showFoo: Boolean = true) {
7+
query Foo($showFoo: Boolean = true @bar(a: 1)) {
88
foo @include(if: $showFoo)
99
}
1010
"""
@@ -13,6 +13,7 @@ defmodule Absinthe.Language.VariableDefinitionTest do
1313
test "builds a VariableDefinition.t" do
1414
assert %Blueprint.Document.VariableDefinition{
1515
name: "showFoo",
16+
directives: [%Blueprint.Directive{name: "bar"}],
1617
type: %Blueprint.TypeReference.Name{name: "Boolean"},
1718
default_value: %Blueprint.Input.Boolean{value: true},
1819
source_location: %Blueprint.SourceLocation{line: 1}

0 commit comments

Comments
 (0)