Sha256: 75811037ede5c42e7f46f42c46de5a5fa3284fb1551b1122d0ebd63784e0097d

Contents?: true

Size: 654 Bytes

Versions: 2

Compression:

Stored size: 654 Bytes

Contents

# Some conveniences for definining fields on {ObjectType}s and {Interface}s.
#
# Passed into initialization blocks, eg {ObjectType#initialize}, {Field#initialize}
class GraphQL::DefinitionHelpers::FieldDefiner
  include Singleton

  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql-0.5.0 lib/graph_ql/definition_helpers/field_definer.rb
graphql-0.4.0 lib/graph_ql/definition_helpers/field_definer.rb