Sha256: b5e461894cdb869f1f29abf437204864455a7dd7c19f4be009325717df39938c

Contents?: true

Size: 1.06 KB

Versions: 115

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module GraphQL
  module Types
    module Relay
      # Include this module to your root Query type to get a Relay-compliant `node(id: ID!): Node` field that uses the schema's `object_from_id` hook.
      module HasNodeField
        def self.included(child_class)
          child_class.field(**field_options, &field_block)
        end

        class << self
          def field_options
            {
              name: "node",
              type: GraphQL::Types::Relay::Node,
              null: true,
              description: "Fetches an object given its ID.",
              relay_node_field: true,
            }
          end

          def field_block
            Proc.new {
              argument :id, "ID!",
                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
  end
end

Version data entries

115 entries across 115 versions & 2 rubygems

Version Path
graphql-2.4.8 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.7 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.6 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.5 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.4 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.3 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.2 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.1 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.0 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.20 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.19 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.18 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.17 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.16 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.15 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.14 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.13 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.12 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.11 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.10 lib/graphql/types/relay/has_node_field.rb