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



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

def all_field_argument_definitions
  dummy.all_argument_definitions
end

#any_field_arguments?Boolean

Returns:

  • (Boolean)


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

def any_field_arguments?
  dummy.any_arguments?
end

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

Also apply this argument to the input type:



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

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
# File 'lib/graphql/schema/has_single_input_argument.rb', line 47

def dummy
  @dummy ||= begin
    d = Class.new(GraphQL::Schema::Resolver)
    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



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

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

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



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

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)



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

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



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

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



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

def own_field_arguments
  dummy.own_arguments
end