Skip to content

Commit

Permalink
Add default empty param when marshalling the node
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavbohac committed Aug 23, 2024
1 parent 7cacd89 commit 0057a90
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/graphql/language/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,17 @@ def scalars
"pos: nil",
"filename: nil",
"source: nil",
"comment: nil"
]

IGNORED_MARSHALLING_KEYWORDS = [:comment]

def generate_initialize
return if method_defined?(:marshal_load, false) # checking for `:initialize` doesn't work right

scalar_method_names = @scalar_methods
# TODO: These probably should be scalar methods, but `types` returns an array
[:types, :description, :comment].each do |extra_method|
[:types, :description].each do |extra_method|
if method_defined?(extra_method)
scalar_method_names += [extra_method]
end
Expand Down Expand Up @@ -307,6 +310,10 @@ def generate_initialize
keywords = scalar_method_names.map { |m| "#{m}: #{m}"} +
children_method_names.map { |m| "#{m}: #{m}" }

ignored_keywords = IGNORED_MARSHALLING_KEYWORDS.map do |keyword|
"#{keyword.to_s}: nil"
end

module_eval <<-RUBY, __FILE__, __LINE__
def initialize(#{arguments.join(", ")})
@line = line
Expand All @@ -317,7 +324,7 @@ def initialize(#{arguments.join(", ")})
#{assignments.join("\n")}
end
def self.from_a(filename, line, col, #{all_method_names.join(", ")})
def self.from_a(filename, line, col, #{all_method_names.join(", ")}, #{ignored_keywords.join(", ")})
self.new(filename: filename, line: line, col: col, #{keywords.join(", ")})
end
Expand Down

0 comments on commit 0057a90

Please sign in to comment.