Sha256: ef448f3ecd238cb7891c16dc01be7b24271c9458313314df0c8e4874d55b029f

Contents?: true

Size: 1.36 KB

Versions: 53

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true
module GraphQL
  module Types
    module Relay
      # This can be used for implementing `Query.nodes(ids: ...)`,
      # or use it for inspiration for your own field definition.
      #
      # @example Adding this field directly
      #   add_field(GraphQL::Types::Relay::NodesField)
      #
      # @example Implementing a similar field in your own Query root
      #
      #   field :nodes, [GraphQL::Types::Relay::Node, null: true], null: false,
      #     description: Fetches a list of objects given a list of IDs." do
      #       argument :ids, [ID], required: true
      #     end
      #
      #   def nodes(ids:)
      #     ids.map do |id|
      #       context.schema.object_from_id(context, id)
      #     end
      #   end
      #
      NodesField = GraphQL::Schema::Field.new(
        name: "nodes",
        owner: nil,
        type: [GraphQL::Types::Relay::Node, null: true],
        null: false,
        description: "Fetches a list of objects given a list of IDs.",
        relay_nodes_field: true,
      ) do
        argument :ids, "[ID!]!", required: true,
          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

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
graphql-1.10.7 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.6 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.5 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.4 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.3 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.2 lib/graphql/types/relay/nodes_field.rb
graphql-1.9.19 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.1 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.0 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.0.pre4 lib/graphql/types/relay/nodes_field.rb
graphql-1.9.18 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.0.pre3 lib/graphql/types/relay/nodes_field.rb
graphql-1.9.17 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.0.pre2 lib/graphql/types/relay/nodes_field.rb
graphql-1.9.16 lib/graphql/types/relay/nodes_field.rb
graphql-1.9.15 lib/graphql/types/relay/nodes_field.rb
graphql-1.9.14 lib/graphql/types/relay/nodes_field.rb
graphql-1.10.0.pre1 lib/graphql/types/relay/nodes_field.rb
graphql-1.9.13 lib/graphql/types/relay/nodes_field.rb
graphql-1.9.12 lib/graphql/types/relay/nodes_field.rb