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

Class Method Details

.field_blockObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/graphql/types/relay/has_nodes_field.rb', line 23

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

    def resolve(obj, args, ctx)
      args[:ids].map { |id| ctx.schema.object_from_id(id, ctx) }
    end

    def resolve_field(obj, args, ctx)
      resolve(obj, args, ctx)
    end
  }
end

.field_optionsObject



13
14
15
16
17
18
19
20
21
# File 'lib/graphql/types/relay/has_nodes_field.rb', line 13

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,
  }
end