Module: DirectiveDefaultsPatch

Defined in:
lib/graph_weaver/directive_defaults_patch.rb

Overview

graphql-ruby's SDL builder (BuildFromDefinition#prepare_directives) passes only the directive arguments present at the usage site, but Directive#initialize validates ALL defined arguments — so a defaulted non-null argument (extension: Boolean! = false) raises InvalidArgumentError when omitted, even though the SDL spec makes it optional. Real Apollo supergraph SDL (join v0.3) hits this on every Fill in the declared defaults before validation. This is what upstream should do; present in graphql 2.6.3 (latest at time of writing).

TODO: delete this file (and its requires) once https://github.com/rmosolgo/graphql-ruby/pull/5659 lands in a released graphql version and the Gemfile picks it up.

Instance Method Summary collapse

Instance Method Details

#initialize(owner, **arguments) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/graph_weaver/directive_defaults_patch.rb', line 21

def initialize(owner, **arguments)
  self.class.all_argument_definitions.each do |arg_defn|
    if !arguments.key?(arg_defn.keyword) && arg_defn.default_value?
      arguments[arg_defn.keyword] = arg_defn.default_value
    end
  end

  super(owner, **arguments)
end