Sha256: 8fdcb9e5c87561c91c76e9cc5ef8ba1f5dcac7c9dbc9c8168a0f77f549a91326

Contents?: true

Size: 1.22 KB

Versions: 39

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true
module GraphQL
  module Types
    module Relay
      # This can be used for implementing `Query.node(id: ...)`,
      # or use it for inspiration for your own field definition.
      #
      # @example Adding this field directly
      #   add_field(GraphQL::Types::Relay::NodeField)
      #
      # @example Implementing a similar field in your own Query root
      #
      #   field :node, GraphQL::Types::Relay::Node, null: true,
      #     description: "Fetches an object given its ID" do
      #       argument :id, ID, required: true
      #     end
      #
      #   def node(id:)
      #     context.schema.object_from_id(id, context)
      #   end
      #
      NodeField = GraphQL::Schema::Field.new(
        name: "node",
        owner: nil,
        type: GraphQL::Types::Relay::Node,
        null: true,
        description: "Fetches an object given its ID.",
        relay_node_field: true,
      ) do
        argument :id, "ID!", required: true,
          description: "ID of the object."

        def resolve(obj, args, ctx)
          ctx.schema.object_from_id(args[:id], ctx)
        end

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

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
graphql-1.11.10 lib/graphql/types/relay/node_field.rb
graphql-1.11.9 lib/graphql/types/relay/node_field.rb
graphql-1.11.8 lib/graphql/types/relay/node_field.rb
graphql-1.11.7 lib/graphql/types/relay/node_field.rb
graphql-1.11.6 lib/graphql/types/relay/node_field.rb
graphql-1.11.5 lib/graphql/types/relay/node_field.rb
graphql-1.11.4 lib/graphql/types/relay/node_field.rb
graphql-1.11.3 lib/graphql/types/relay/node_field.rb
graphql-1.11.2 lib/graphql/types/relay/node_field.rb
graphql-1.10.14 lib/graphql/types/relay/node_field.rb
graphql-1.11.1 lib/graphql/types/relay/node_field.rb
graphql-1.10.13 lib/graphql/types/relay/node_field.rb
graphql-1.11.0 lib/graphql/types/relay/node_field.rb
graphql-1.10.12 lib/graphql/types/relay/node_field.rb
graphql-1.9.21 lib/graphql/types/relay/node_field.rb
graphql-1.10.11 lib/graphql/types/relay/node_field.rb
graphql-1.9.20 lib/graphql/types/relay/node_field.rb
graphql-1.10.10 lib/graphql/types/relay/node_field.rb
graphql-1.10.9 lib/graphql/types/relay/node_field.rb
graphql-1.10.8 lib/graphql/types/relay/node_field.rb