Sha256: 135009a573c98444806b3930eac6a764e220da16a1e207f878bfe62dcb0f1f9e

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

# This type exposes fields on an object.
#
#  @example defining a type for your IMDB clone
#    MovieType = GraphQL::ObjectType.define do
#      name "Movie"
#      description "A full-length film or a short film"
#      interfaces [ProductionInterface, DurationInterface]
#
#      field :runtimeMinutes, !types.Int, property: :runtime_minutes
#      field :director, PersonType
#      field :cast, CastType
#      field :starring, types[PersonType] do
#        arguments :limit, types.Int
#        resolve -> (object, args, ctx) {
#          stars = object.cast.stars
#          args[:limit] && stars = stars.limit(args[:limit])
#          stars
#        }
#       end
#    end
#
class GraphQL::ObjectType < GraphQL::BaseType
  defined_by_config :name, :description, :interfaces, :fields
  attr_accessor :name, :description, :interfaces, :fields

  # Define fields to be `new_fields`, normalize with {StringNamedHash}
  # @param new_fields [Hash] The fields exposed by this type
  def fields=(new_fields)
    @fields = GraphQL::DefinitionHelpers::StringNamedHash.new(new_fields).to_h
  end

  #   Shovel this type into each interface's `possible_types` array.
  #
  #   @param new_interfaces [Array<GraphQL::Interface>] interfaces that this type implements
  def interfaces=(new_interfaces)
    @interfaces ||= []
    (@interfaces - new_interfaces).each { |i| i.possible_types.delete(self) }
    (new_interfaces - @interfaces).each { |i| i.possible_types << self }
    @interfaces = new_interfaces
  end

  def kind
    GraphQL::TypeKinds::OBJECT
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql-0.11.0 lib/graphql/object_type.rb
graphql-0.10.9 lib/graphql/object_type.rb