Class: GraphQL::InterfaceType

Inherits:
ObjectType show all
Defined in:
lib/graph_ql/interface_type.rb

Overview

A collection of types which implement the same fields

Examples:

An interface with three required fields

DeviceInterface = GraphQL::InterfaceType.new do |i, types, fields|
  i.name("Device")
  i.description("Hardware devices for computing")
  i.fields({
    ram:          fields.build(type: types.String),
    processor:    fields.build(type: ProcessorType),
    release_year: fields.build(type: types.Int),
  })
end

Instance Method Summary collapse

Methods inherited from ObjectType

#==, #fields, #fields=, #initialize, #interfaces, #to_s

Methods included from DefinitionHelpers::Definable

#attr_definable

Methods included from DefinitionHelpers::NonNullWithBang

#!

Constructor Details

This class inherits a constructor from GraphQL::ObjectType

Instance Method Details

#kindObject



15
16
17
# File 'lib/graph_ql/interface_type.rb', line 15

def kind
  GraphQL::TypeKinds::INTERFACE
end

#possible_typesArray<GraphQL::ObjectType>

Returns Types which declare that they implement this interface.

Returns:



20
21
22
# File 'lib/graph_ql/interface_type.rb', line 20

def possible_types
  @possible_types ||= []
end

#resolve_type(object) ⇒ GraphQL::ObjectType

Return the implementing type for ‘object`. The default implementation assumes that there’s a type with the same name as ‘object.class.name`. Maybe you’ll need to override this in your own interfaces!

Parameters:

  • object (Object)

    the object which needs a type to expose it

Returns:



30
31
32
# File 'lib/graph_ql/interface_type.rb', line 30

def resolve_type(object)
  @possible_types.find {|t| t.name == object.class.name }
end