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.10.7 lib/graphql/types/relay/node_field.rb
graphql-1.10.6 lib/graphql/types/relay/node_field.rb
graphql-1.10.5 lib/graphql/types/relay/node_field.rb
graphql-1.10.4 lib/graphql/types/relay/node_field.rb
graphql-1.10.3 lib/graphql/types/relay/node_field.rb
graphql-1.10.2 lib/graphql/types/relay/node_field.rb
graphql-1.9.19 lib/graphql/types/relay/node_field.rb
graphql-1.10.1 lib/graphql/types/relay/node_field.rb
graphql-1.10.0 lib/graphql/types/relay/node_field.rb
graphql-1.10.0.pre4 lib/graphql/types/relay/node_field.rb
graphql-1.9.18 lib/graphql/types/relay/node_field.rb
graphql-1.10.0.pre3 lib/graphql/types/relay/node_field.rb
graphql-1.9.17 lib/graphql/types/relay/node_field.rb
graphql-1.10.0.pre2 lib/graphql/types/relay/node_field.rb
graphql-1.9.16 lib/graphql/types/relay/node_field.rb
graphql-1.9.15 lib/graphql/types/relay/node_field.rb
graphql-1.9.14 lib/graphql/types/relay/node_field.rb
graphql-1.10.0.pre1 lib/graphql/types/relay/node_field.rb
graphql-1.9.13 lib/graphql/types/relay/node_field.rb