Module: GraphQL::Define::AssignObjectField
- Defined in:
- lib/graphql/define/assign_object_field.rb
Overview
Turn field configs into a Field and attach it to a ObjectType or InterfaceType
Class Method Summary collapse
Class Method Details
.call(owner_type, name, type_or_field = nil, desc = nil, field: nil, **kwargs, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/graphql/define/assign_object_field.rb', line 5 def self.call(owner_type, name, type_or_field = nil, desc = nil, field: nil, **kwargs, &block) name_s = name.to_s # Move some possitional definitions into keyword defns: kwargs[:description] ||= desc kwargs[:name] ||= name_s if !type_or_field.nil? && !type_or_field.is_a?(GraphQL::Field) kwargs[:type] = type_or_field end # Figure out how to find or initialize the field instance: if type_or_field.is_a?(GraphQL::Field) field = type_or_field field.name ||= name_s elsif block_given? field = GraphQL::Field.define(kwargs, &block) elsif field.nil? field = GraphQL::Field.define(kwargs) elsif field.is_a?(GraphQL::Field) field.name ||= name_s else raise("Couldn't find a field argument, received: #{field || type_or_field}") end # Attach the field to the type owner_type.fields[name_s] = field end |