Module: GraphQL::Schema::Resolver::HasPayloadType

Included in:
Mutation, Subscription
Defined in:
lib/graphql/schema/resolver/has_payload_type.rb

Overview

Adds field(...) helper to resolvers so that they can generate payload types.

Or, an already-defined one can be attached with payload_type(...).

Instance Method Summary collapse

Instance Method Details

#field_class(new_class = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/graphql/schema/resolver/has_payload_type.rb', line 26

def field_class(new_class = nil)
  if new_class
    @field_class = new_class
  elsif defined?(@field_class) && @field_class
    @field_class
  else
    find_inherited_value(:field_class, GraphQL::Schema::Field)
  end
end

#object_class(new_class = nil) ⇒ Class

An object class to use for deriving return types

Parameters:

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

    Defaults to Object

Returns:

  • (Class)


39
40
41
42
43
44
45
# File 'lib/graphql/schema/resolver/has_payload_type.rb', line 39

def object_class(new_class = nil)
  if new_class
    @object_class = new_class
  else
    @object_class || find_inherited_value(:object_class, GraphQL::Schema::Object)
  end
end

#payload_type(new_payload_type = nil) ⇒ Class Also known as: type, type_expr

Call this method to get the derived return type of the mutation, or use it as a configuration method to assign a return type instead of generating one.

Parameters:

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

    If a type definition class is provided, it will be used as the return type of the mutation field

Returns:

  • (Class)

    The object type which this mutation returns.



16
17
18
19
20
21
# File 'lib/graphql/schema/resolver/has_payload_type.rb', line 16

def payload_type(new_payload_type = nil)
  if new_payload_type
    @payload_type = new_payload_type
  end
  @payload_type ||= generate_payload_type
end