Module: GraphQL::Schema::HasSingleInputArgument::ClassMethods

Defined in:
lib/graphql/schema/has_single_input_argument.rb

Instance Method Summary collapse

Instance Method Details

#all_field_argument_definitionsObject



74
75
76
# File 'lib/graphql/schema/has_single_input_argument.rb', line 74

def all_field_argument_definitions
  dummy.all_argument_definitions
end

#any_field_arguments?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/graphql/schema/has_single_input_argument.rb', line 70

def any_field_arguments?
  dummy.any_arguments?
end

#argument(*args, own_argument: false, **kwargs, &block) ⇒ Object

Also apply this argument to the input type:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/graphql/schema/has_single_input_argument.rb', line 79

def argument(*args, own_argument: false, **kwargs, &block)
  it = input_type # make sure any inherited arguments are already added to it
  arg = super(*args, **kwargs, &block)

  # This definition might be overriding something inherited;
  # if it is, remove the inherited definition so it's not confused at runtime as having multiple definitions
  prev_args = it.own_arguments[arg.graphql_name]
  case prev_args
  when GraphQL::Schema::Argument
    if prev_args.owner != self
      it.own_arguments.delete(arg.graphql_name)
    end
  when Array
    prev_args.reject! { |a| a.owner != self }
    if prev_args.empty?
      it.own_arguments.delete(arg.graphql_name)
    end
  end

  it.add_argument(arg)
  arg
end

#dummyObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/graphql/schema/has_single_input_argument.rb', line 47

def dummy
  @dummy ||= begin
    d = Class.new(GraphQL::Schema::Resolver)
    d.graphql_name "#{self.graphql_name}DummyResolver"
    d.argument_class(self.argument_class)
    # TODO make this lazier?
    d.argument(:input, input_type, description: "Parameters for #{self.graphql_name}")
    d
  end
end

#field_arguments(context = GraphQL::Query::NullContext.instance) ⇒ Object



58
59
60
# File 'lib/graphql/schema/has_single_input_argument.rb', line 58

def field_arguments(context = GraphQL::Query::NullContext.instance)
  dummy.arguments(context)
end

#get_field_argument(name, context = GraphQL::Query::NullContext.instance) ⇒ Object



62
63
64
# File 'lib/graphql/schema/has_single_input_argument.rb', line 62

def get_field_argument(name, context = GraphQL::Query::NullContext.instance)
  dummy.get_argument(name, context)
end

#input_object_class(new_class = nil) ⇒ Class

The base class for generated input object types

Parameters:

  • new_class (Class) (defaults to: nil)

    The base class to use for generating input object definitions

Returns:

  • (Class)

    The base class for this mutation's generated input object (default is InputObject)



105
106
107
108
109
110
# File 'lib/graphql/schema/has_single_input_argument.rb', line 105

def input_object_class(new_class = nil)
  if new_class
    @input_object_class = new_class
  end
  @input_object_class || (superclass.respond_to?(:input_object_class) ? superclass.input_object_class : GraphQL::Schema::InputObject)
end

#input_type(new_input_type = nil) ⇒ Class

Returns The generated InputObject class for this mutation's input.

Parameters:

  • new_input_type (Class, nil) (defaults to: nil)

    If provided, it configures this mutation to accept new_input_type instead of generating an input type

Returns:

  • (Class)

    The generated InputObject class for this mutation's input



114
115
116
117
118
119
# File 'lib/graphql/schema/has_single_input_argument.rb', line 114

def input_type(new_input_type = nil)
  if new_input_type
    @input_type = new_input_type
  end
  @input_type ||= generate_input_type
end

#own_field_argumentsObject



66
67
68
# File 'lib/graphql/schema/has_single_input_argument.rb', line 66

def own_field_arguments
  dummy.own_arguments
end