Sha256: b5e461894cdb869f1f29abf437204864455a7dd7c19f4be009325717df39938c

Contents?: true

Size: 1.06 KB

Versions: 129

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

129 entries across 129 versions & 2 rubygems

Version Path
graphql-2.4.15 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.14 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.22 lib/graphql/types/relay/has_node_field.rb
graphql-2.1.15 lib/graphql/types/relay/has_node_field.rb
graphql-1.13.24 lib/graphql/types/relay/has_node_field.rb
graphql-2.0.32 lib/graphql/types/relay/has_node_field.rb
graphql-2.1.14 lib/graphql/types/relay/has_node_field.rb
graphql-2.2.17 lib/graphql/types/relay/has_node_field.rb
graphql-2.3.21 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.13 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.12 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.11 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.10 lib/graphql/types/relay/has_node_field.rb
graphql-2.4.9 lib/graphql/types/relay/has_node_field.rb
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