Module: GraphQL::Types::Relay::HasNodesField

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

Overview

Include this module to your root Query type to get a Relay-style nodes(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_nodes_field.rb', line 28

def field_block
  Proc.new {
    argument :ids, "[ID!]!",
      description: "IDs of the objects."
  }
end

.field_optionsObject



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

def field_options
  {
    name: "nodes",
    type: [GraphQL::Types::Relay::Node, null: true],
    null: false,
    description: "Fetches a list of objects given a list of IDs.",
    relay_nodes_field: true,
    resolver_method: :get_relay_nodes
  }
end

Instance Method Details

#get_relay_nodes(ids:) ⇒ Object



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

def get_relay_nodes(ids:)
  ids.map { |id| context.schema.object_from_id(id, context) }
end