class GraphQL::Function

@api deprecated

Public Class Methods

argument(*args, **kwargs, &block) click to toggle source

Define an argument for this function & its subclasses @see {GraphQL::Field} same arguments as the `argument` definition helper @return [void]

# File lib/graphql/function.rb, line 43
def argument(*args, **kwargs, &block)
  argument = GraphQL::Argument.from_dsl(*args, **kwargs, &block)
  own_arguments[argument.name] = argument
  nil
end
arguments() click to toggle source

@return [Hash<String => GraphQL::Argument>] Arguments for this function class, including inherited arguments

# File lib/graphql/function.rb, line 50
def arguments
  if parent_function?
    own_arguments.merge(superclass.arguments)
  else
    own_arguments.dup
  end
end
build_field(function) click to toggle source
# File lib/graphql/function.rb, line 77
def build_field(function)
  GraphQL::Field.define(
    arguments: function.arguments,
    complexity: function.complexity,
    type: function.type,
    resolve: function,
    description: function.description,
    function: function,
    deprecation_reason: function.deprecation_reason,
  )
end
inherited(subclass) click to toggle source
# File lib/graphql/function.rb, line 5
def self.inherited(subclass)
  GraphQL::Deprecation.warn "GraphQL::Function (used for #{subclass}) will be removed from GraphQL-Ruby 2.0, please upgrade to resolvers: https://graphql-ruby.org/fields/resolvers.html"
end
inherited_value(name) click to toggle source

Class-level reader/writer which is inherited @api private

# File lib/graphql/function.rb, line 91
      def self.inherited_value(name)
        self.class_eval <<-RUBY
          def #{name}(new_value = nil)
            if new_value
              @#{name} = new_value
            elsif parent_function?
              @#{name} || superclass.#{name}
            else
              @#{name}
            end
          end
        RUBY
      end
type(premade_type = nil, &block) click to toggle source

Get or set the return type for this function class & descendants @return [GraphQL::BaseType]

# File lib/graphql/function.rb, line 65
def type(premade_type = nil, &block)
  if block_given?
    @type = GraphQL::ObjectType.define(&block)
  elsif premade_type
    @type = premade_type
  elsif parent_function?
    @type || superclass.type
  else
    @type
  end
end
types() click to toggle source

Provides shorthand access to GraphQL's built-in types

# File lib/graphql/function.rb, line 59
def types
  GraphQL::Define::TypeDefiner.instance
end

Private Class Methods

own_arguments() click to toggle source

Arguments defined on this class (not superclasses)

# File lib/graphql/function.rb, line 123
def own_arguments
  @own_arguments ||= {}
end
parent_function?() click to toggle source

Does this function inherit from another function?

# File lib/graphql/function.rb, line 118
def parent_function?
  superclass <= GraphQL::Function
end

Public Instance Methods

arguments() click to toggle source

@return [Hash<String => GraphQL::Argument>] Arguments, keyed by name

# File lib/graphql/function.rb, line 10
def arguments
  self.class.arguments
end
call(obj, args, ctx) click to toggle source

@return [Object] This function's resolver

# File lib/graphql/function.rb, line 20
def call(obj, args, ctx)
  raise GraphQL::RequiredImplementationMissingError
end
complexity() click to toggle source

@return [Integer, Proc]

# File lib/graphql/function.rb, line 35
def complexity
  self.class.complexity || 1
end
deprecation_reason() click to toggle source

@return [String, nil]

# File lib/graphql/function.rb, line 30
def deprecation_reason
  self.class.deprecation_reason
end
description() click to toggle source

@return [String, nil]

# File lib/graphql/function.rb, line 25
def description
  self.class.description
end
type() click to toggle source

@return [GraphQL::BaseType] Return type

# File lib/graphql/function.rb, line 15
def type
  self.class.type
end