Sha256: 84989486e17950a8ff5a6884dfd86a5a42692d5a5dddc31353d176859e43d716

Contents?: true

Size: 980 Bytes

Versions: 13

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

module GraphQL
  module Types
    module Relay
      module HasNodeField
        def self.included(child_class)
          child_class.field(**field_options, &field_block)
        end

        class << self
          def field_options
            {
              name: "node",
              owner: nil,
              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!", 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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql-1.12.12 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.11 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.10 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.9 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.8 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.7 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.6 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.5 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.4 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.3 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.2 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.1 lib/graphql/types/relay/has_node_field.rb
graphql-1.12.0 lib/graphql/types/relay/has_node_field.rb