Class: GraphQL::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/function.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.argument(*args, **kwargs, &block) ⇒ void

This method returns an undefined value.

Define an argument for this function & its subclasses

See Also:

  • same arguments as the `argument` definition helper


43
44
45
46
47
# 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

.argumentsHash<String => GraphQL::Argument>

Returns Arguments for this function class, including inherited arguments.

Returns:

  • (Hash<String => GraphQL::Argument>)

    Arguments for this function class, including inherited arguments



50
51
52
53
54
55
56
# 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) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# 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

.complexity(new_value = nil) ⇒ Object

Get or set this class's complexity



113
# File 'lib/graphql/function.rb', line 113

inherited_value(:complexity)

.deprecation_reason(new_value = nil) ⇒ Object

Get or set this class's deprecation_reason



110
# File 'lib/graphql/function.rb', line 110

inherited_value(:deprecation_reason)

.description(new_value = nil) ⇒ Object

Get or set this class's description



107
# File 'lib/graphql/function.rb', line 107

inherited_value(:description)

.inherited_value(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Class-level reader/writer which is inherited



91
92
93
94
95
96
97
98
99
100
101
102
103
# 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) ⇒ GraphQL::BaseType

Get or set the return type for this function class & descendants

Returns:



65
66
67
68
69
70
71
72
73
74
75
# 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

.typesObject

Provides shorthand access to GraphQL's built-in types



59
60
61
# File 'lib/graphql/function.rb', line 59

def types
  GraphQL::Define::TypeDefiner.instance
end

Instance Method Details

#argumentsHash<String => GraphQL::Argument>

Returns Arguments, keyed by name.

Returns:



10
11
12
# File 'lib/graphql/function.rb', line 10

def arguments
  self.class.arguments
end

#call(obj, args, ctx) ⇒ Object

Returns This function's resolver.

Returns:

  • (Object)

    This function's resolver

Raises:



20
21
22
# File 'lib/graphql/function.rb', line 20

def call(obj, args, ctx)
  raise GraphQL::RequiredImplementationMissingError
end

#complexityInteger, Proc

Returns:

  • (Integer, Proc)


35
36
37
# File 'lib/graphql/function.rb', line 35

def complexity
  self.class.complexity || 1
end

#deprecation_reasonString?

Returns:

  • (String, nil)


30
31
32
# File 'lib/graphql/function.rb', line 30

def deprecation_reason
  self.class.deprecation_reason
end

#descriptionString?

Returns:

  • (String, nil)


25
26
27
# File 'lib/graphql/function.rb', line 25

def description
  self.class.description
end

#typeGraphQL::BaseType

Return type

Returns:



15
16
17
# File 'lib/graphql/function.rb', line 15

def type
  self.class.type
end