Sha256: cf393db465e70e8e2fc101f3118dd59995f39a4c0966f0eab7ae7ad20a76831c

Contents?: true

Size: 607 Bytes

Versions: 1

Compression:

Stored size: 607 Bytes

Contents

module GraphQL
  module Relay
    # @example Create a field that returns the global ID for an object
    #   RestaurantType = GraphQL::ObjectType.define do
    #     name "Restaurant"
    #     field :id, field: GraphQL::Relay::GlobalIdField.new("Restaurant")
    #   end
    class GlobalIdField < GraphQL::Field
      def initialize(type_name, property: :id)
        self.arguments = {}
        self.type = !GraphQL::ID_TYPE
        self.resolve = -> (obj, args, ctx) {
          ctx.query.schema.node_identification.to_global_id(type_name, obj.public_send(property))
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql-relay-0.12.0 lib/graphql/relay/global_id_field.rb