Sha256: cc9d30a831101e30d3b154ef447729e043fc1a3005809f58926ebd256562910e

Contents?: true

Size: 1.12 KB

Versions: 117

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module GraphQL
  module Types
    module Relay
      # 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.
      module HasNodesField
        def self.included(child_class)
          child_class.field(**field_options, &field_block)
        end

        class << self
          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

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

Version data entries

117 entries across 117 versions & 2 rubygems

Version Path
graphql-1.13.19 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.13.18 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.16 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.13.17 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.15 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.14 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.13.16 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.13 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.12 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.13.15 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.11 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.13.14 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.13.13 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.9 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.8 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.7 lib/graphql/types/relay/has_nodes_field.rb
graphql_cody-1.13.0 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.13.12 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.6 lib/graphql/types/relay/has_nodes_field.rb
graphql-2.0.5 lib/graphql/types/relay/has_nodes_field.rb