Sha256: 861a5acc407cbbf366b2a2f46f267689ebb95e914c344810762ba428c5860213

Contents?: true

Size: 1.31 KB

Versions: 55

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true
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, function: nil, field: nil, relay_mutation_function: nil, **kwargs, &block)
        name_s = name.to_s

        # Move some positional args into keywords if they're present
        desc && kwargs[:description] ||= desc
        name && kwargs[:name] ||= name_s

        if !type_or_field.nil? && !type_or_field.is_a?(GraphQL::Field)
          # Maybe a string, proc or BaseType
          kwargs[:type] = type_or_field
        end

        base_field = if type_or_field.is_a?(GraphQL::Field)
          type_or_field.redefine(name: name_s)
        elsif function
          func_field = GraphQL::Function.build_field(function)
          func_field.name = name_s
          func_field
        elsif field.is_a?(GraphQL::Field)
          field.redefine(name: name_s)
        else
          nil
        end

        obj_field = if base_field
          base_field.redefine(kwargs, &block)
        else
          GraphQL::Field.define(kwargs, &block)
        end


        # Attach the field to the type
        owner_type.fields[name_s] = obj_field
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
graphql-1.8.18 lib/graphql/define/assign_object_field.rb
graphql-1.10.0.pre3 lib/graphql/define/assign_object_field.rb
graphql-1.9.17 lib/graphql/define/assign_object_field.rb
graphql-1.10.0.pre2 lib/graphql/define/assign_object_field.rb
graphql-1.9.16 lib/graphql/define/assign_object_field.rb
graphql-1.9.15 lib/graphql/define/assign_object_field.rb
graphql-1.9.14 lib/graphql/define/assign_object_field.rb
graphql-1.10.0.pre1 lib/graphql/define/assign_object_field.rb
graphql-1.9.13 lib/graphql/define/assign_object_field.rb
graphql-1.9.12 lib/graphql/define/assign_object_field.rb
graphql-1.9.11 lib/graphql/define/assign_object_field.rb
graphql-1.9.10 lib/graphql/define/assign_object_field.rb
graphql-1.9.9 lib/graphql/define/assign_object_field.rb
graphql-1.9.8 lib/graphql/define/assign_object_field.rb
graphql-1.9.7 lib/graphql/define/assign_object_field.rb
graphql-1.9.6 lib/graphql/define/assign_object_field.rb
graphql-1.9.5 lib/graphql/define/assign_object_field.rb
graphql-1.9.4 lib/graphql/define/assign_object_field.rb
graphql-1.9.3 lib/graphql/define/assign_object_field.rb
graphql-1.9.2 lib/graphql/define/assign_object_field.rb