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, #initialize_copy, #metadata, #redefine

Constructor Details

#initializeMutation

Returns a new instance of Mutation.



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

def initialize
  @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



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

def return_interfaces
  @return_interfaces ||= []
end

#return_typeObject



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

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



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

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)


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

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



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

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



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

def resolve=(new_resolve_proc)
  @resolve_proc = new_resolve_proc
end

#result_classObject



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

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