Module: GraphQL::Types::Relay::HasNodeField

Defined in:
lib/graphql/types/relay/has_node_field.rb

Overview

Include this module to your root Query type to get a Relay-compliant node(id: ID!): Node field that uses the schema’s object_from_id hook.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.field_blockObject



28
29
30
31
32
33
# File 'lib/graphql/types/relay/has_node_field.rb', line 28

def field_block
  Proc.new {
    argument :id, "ID!",
      description: "ID of the object."
  }
end

.field_optionsObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/graphql/types/relay/has_node_field.rb', line 17

def field_options
  {
    name: "node",
    type: GraphQL::Types::Relay::Node,
    null: true,
    description: "Fetches an object given its ID.",
    relay_node_field: true,
    resolver_method: :get_relay_node
  }
end

Instance Method Details

#get_relay_node(id:) ⇒ Object



12
13
14
# File 'lib/graphql/types/relay/has_node_field.rb', line 12

def get_relay_node(id:)
  context.schema.object_from_id(id, context)
end