Class: GraphQL::DefinitionHelpers::FieldDefiner

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/graph_ql/definition_helpers/field_definer.rb

Overview

Some conveniences for definining fields on ObjectTypes and Interfaces.

Passed into initialization blocks, eg ObjectType#initialize, Field#initialize

Instance Method Summary collapse

Instance Method Details

#build(type:, args: {}, property: nil, desc: "", deprecation_reason: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/graph_ql/definition_helpers/field_definer.rb', line 7

def build(type:, args: {}, property: nil, desc: "", deprecation_reason: nil)
  resolve = if property.nil?
    -> (o, a, c)  { GraphQL::Query::DEFAULT_RESOLVE }
  else
    -> (object, a, c) { object.send(property) }
  end

  GraphQL::Field.new do |f|
    f.type(type)
    f.arguments(args)
    f.description(desc)
    f.resolve(resolve)
    f.deprecation_reason(deprecation_reason)
  end
end