Skip to content

Commit

Permalink
Set DirectiveDefinitionNode.children_method_name
Browse files Browse the repository at this point in the history
This commit sets `DirectiveDefinitionNode.children_method_name` to
`:definitions`. It previously defaulted to `:directive_definitions`,
causing a `NoMethodError` when attempting to delete the node from the
AST.
  • Loading branch information
thomasmarshall committed Apr 23, 2024
1 parent 43bbe01 commit 221db86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/graphql/language/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ class DirectiveDefinition < AbstractNode
arguments: Nodes::Argument,
locations: Nodes::DirectiveLocation,
)
self.children_method_name = :definitions
end

# An enum value. The string is available as {#name}.
Expand Down
14 changes: 14 additions & 0 deletions spec/graphql/language/visitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ def on_variable_definition(node, parent)
super
end
end

def on_directive_definition(node, parent)
if node.name == "deleteMe"
super(DELETE_NODE, parent)
else
super
end
end
end

def get_result(query_str)
Expand Down Expand Up @@ -375,6 +383,10 @@ def get_result(query_str)

it "works with SDL" do
before_query = <<-GRAPHQL.chop
directive @deleteMe on FIELD
directive @keepMe on FIELD
type Rename @doStuff {
f: Int
renameThis: String
Expand All @@ -383,6 +395,8 @@ def get_result(query_str)
GRAPHQL

after_query = <<-GRAPHQL.chop
directive @keepMe on FIELD
type WasRenamed @doStuff(addedArgument2: 2) {
f: Int
wasRenamed: String
Expand Down

0 comments on commit 221db86

Please sign in to comment.