Class: GraphQL::FieldDefiner

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

Overview

Every Node class has a FieldDefiner instance that enables the ‘field.something` API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_class) ⇒ FieldDefiner

Returns a new instance of FieldDefiner.



5
6
7
# File 'lib/graphql/field_definer.rb', line 5

def initialize(owner_class)
  @owner_class = owner_class
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

‘method_name` is used as a field type and looked up against SCHEMA. `args` is the name for the field of that type.



11
12
13
14
15
16
17
18
# File 'lib/graphql/field_definer.rb', line 11

def method_missing(method_name, *args, &block)
  type = GraphQL::SCHEMA.get_field(method_name)
  if type.present?
    create_field(args[0], type: type, description: args[1])
  else
    super
  end
end

Instance Attribute Details

#owner_classObject (readonly)

Returns the value of attribute owner_class.



4
5
6
# File 'lib/graphql/field_definer.rb', line 4

def owner_class
  @owner_class
end