Sha256: ede9ab0da31d368de8b6850ebf16b3124a58d357c275c3dd5438d531a2daa7ce

Contents?: true

Size: 1.54 KB

Versions: 34

Compression:

Stored size: 1.54 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
          GraphQL::Field.define(
            arguments: function.arguments,
            complexity: function.complexity,
            name: name_s,
            type: function.type,
            resolve: function,
            description: function.description,
            function: function,
            deprecation_reason: function.deprecation_reason,
          )
        elsif field.is_a?(GraphQL::Field)
          field.redefine(name: name_s)
        else
          nil
        end

        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] = field
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
graphql-1.7.14 lib/graphql/define/assign_object_field.rb
graphql-1.7.13 lib/graphql/define/assign_object_field.rb
graphql-1.7.12 lib/graphql/define/assign_object_field.rb
graphql-1.7.11 lib/graphql/define/assign_object_field.rb
graphql-1.7.10 lib/graphql/define/assign_object_field.rb
graphql-1.7.9 lib/graphql/define/assign_object_field.rb
graphql-1.7.8 lib/graphql/define/assign_object_field.rb
graphql-1.7.7 lib/graphql/define/assign_object_field.rb
graphql-1.7.6 lib/graphql/define/assign_object_field.rb
graphql-1.7.5 lib/graphql/define/assign_object_field.rb
graphql-1.7.4 lib/graphql/define/assign_object_field.rb
graphql-1.7.3 lib/graphql/define/assign_object_field.rb
graphql-1.7.2 lib/graphql/define/assign_object_field.rb
graphql-1.7.1 lib/graphql/define/assign_object_field.rb
graphql-1.7.0 lib/graphql/define/assign_object_field.rb
graphql-1.6.8 lib/graphql/define/assign_object_field.rb
graphql-1.6.7 lib/graphql/define/assign_object_field.rb
graphql-1.6.6 lib/graphql/define/assign_object_field.rb
graphql-1.6.5 lib/graphql/define/assign_object_field.rb
graphql-1.6.4 lib/graphql/define/assign_object_field.rb