Class: GraphQL::Relay::Mutation

Inherits:
Object
  • Object
show all
Includes:
Define::InstanceDefinable
Defined in:
lib/graphql/relay/mutation.rb,
lib/graphql/relay/mutation/result.rb,
lib/graphql/relay/mutation/resolve.rb,
lib/graphql/relay/mutation/instrumentation.rb

Defined Under Namespace

Modules: Instrumentation Classes: Resolve, Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Define::InstanceDefinable

#define, #deprecated_define, #initialize_copy, #metadata, #redefine

Constructor Details

#initializeMutation

Returns a new instance of Mutation.



32
33
34
35
36
37
# File 'lib/graphql/relay/mutation.rb', line 32

def initialize
  GraphQL::Deprecation.warn "GraphQL::Relay::Mutation will be removed from GraphQL-Ruby 2.0, use GraphQL::Schema::RelayClassicMutation instead: https://graphql-ruby.org/mutations/mutation_classes"
  @fields = {}
  @arguments = {}
  @has_generated_return_type = false
end

Instance Attribute Details

#argumentsObject Also known as: input_fields



19
20
21
# File 'lib/graphql/relay/mutation.rb', line 19

def arguments
  @arguments
end

#descriptionObject



19
20
21
# File 'lib/graphql/relay/mutation.rb', line 19

def description
  @description
end

#fieldsObject Also known as: return_fields



19
20
21
# File 'lib/graphql/relay/mutation.rb', line 19

def fields
  @fields
end

#nameObject



19
20
21
# File 'lib/graphql/relay/mutation.rb', line 19

def name
  @name
end

#return_interfacesObject



63
64
65
# File 'lib/graphql/relay/mutation.rb', line 63

def return_interfaces
  @return_interfaces ||= []
end

#return_typeObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/graphql/relay/mutation.rb', line 67

def return_type
  @return_type ||= begin
    @has_generated_return_type = true
    relay_mutation = self
    GraphQL::ObjectType.define do
      name("#{relay_mutation.name}Payload")
      description("Autogenerated return type of #{relay_mutation.name}")
      field :clientMutationId, types.String, "A unique identifier for the client performing the mutation.", property: :client_mutation_id
      interfaces relay_mutation.return_interfaces
      relay_mutation.return_fields.each do |name, field_obj|
        field name, field: field_obj
      end
      mutation(relay_mutation)
    end
  end
end

Instance Method Details

#fieldObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/graphql/relay/mutation.rb', line 49

def field
  @field ||= begin
    relay_mutation = self
    field_resolve_proc = @resolve_proc
    GraphQL::Field.define do
      type(relay_mutation.return_type)
      description(relay_mutation.description)
      argument :input, !relay_mutation.input_type
      resolve(field_resolve_proc)
      mutation(relay_mutation)
    end
  end
end

#has_generated_return_type?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/graphql/relay/mutation.rb', line 39

def has_generated_return_type?
  # Trigger the generation of the return type, if it is dynamically generated:
  return_type
  @has_generated_return_type
end

#input_typeObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/graphql/relay/mutation.rb', line 84

def input_type
  @input_type ||= begin
    relay_mutation = self
    input_object_type = GraphQL::InputObjectType.define do
      name("#{relay_mutation.name}Input")
      description("Autogenerated input type of #{relay_mutation.name}")
      input_field :clientMutationId, types.String, "A unique identifier for the client performing the mutation."
      mutation(relay_mutation)
    end
    input_fields.each do |name, arg|
      input_object_type.arguments[name] = arg
    end

    input_object_type
  end
end

#resolve=(new_resolve_proc) ⇒ Object



45
46
47
# File 'lib/graphql/relay/mutation.rb', line 45

def resolve=(new_resolve_proc)
  @resolve_proc = new_resolve_proc
end

#result_classObject



101
102
103
# File 'lib/graphql/relay/mutation.rb', line 101

def result_class
  @result_class ||= Result.define_subclass(self)
end