Sha256: 0d2cee0da4a3962096173c8ebc0d5ffb4cfbf5035067bfa222f56229ff1268c6

Contents?: true

Size: 1.17 KB

Versions: 28

Compression:

Stored size: 1.17 KB

Contents

module GraphQL
  module Define
    # Turn field configs into a {GraphQL::Field} and attach it to a {GraphQL::ObjectType} or {GraphQL::InterfaceType}
    module AssignObjectField
      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
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
graphql-1.2.4 lib/graphql/define/assign_object_field.rb
graphql-1.2.3 lib/graphql/define/assign_object_field.rb
graphql-1.2.2 lib/graphql/define/assign_object_field.rb
graphql-1.2.1 lib/graphql/define/assign_object_field.rb
graphql-1.2.0 lib/graphql/define/assign_object_field.rb
graphql-1.1.0 lib/graphql/define/assign_object_field.rb
graphql-1.0.0 lib/graphql/define/assign_object_field.rb
graphql-0.19.4 lib/graphql/define/assign_object_field.rb
graphql-0.19.3 lib/graphql/define/assign_object_field.rb
graphql-0.19.2 lib/graphql/define/assign_object_field.rb
graphql-0.19.1 lib/graphql/define/assign_object_field.rb
graphql-0.19.0 lib/graphql/define/assign_object_field.rb
graphql-0.18.15 lib/graphql/define/assign_object_field.rb
graphql-0.18.14 lib/graphql/define/assign_object_field.rb
graphql-0.18.13 lib/graphql/define/assign_object_field.rb
graphql-0.18.12 lib/graphql/define/assign_object_field.rb
graphql-0.18.11 lib/graphql/define/assign_object_field.rb
graphql-0.18.10 lib/graphql/define/assign_object_field.rb
graphql-0.18.9 lib/graphql/define/assign_object_field.rb
graphql-0.18.8 lib/graphql/define/assign_object_field.rb