Class: GraphQL::InterfaceType

Inherits:
BaseType
  • Object
show all
Defined in:
lib/graphql/interface_type.rb

Overview

An Interface contains a collection of types which implement some of the same fields.

Interfaces can have fields, defined with field, just like an object type.

Objects which implement this field inherit field definitions from the interface. An object type can override the inherited definition by redefining that field.

Examples:

An interface with three fields

DeviceInterface = GraphQL::InterfaceType.define do
  name("Device")
  description("Hardware devices for computing")

  field :ram, types.String
  field :processor, ProcessorType
  field :release_year, types.Int
end

Implementing an interface with an object type

Laptoptype = GraphQL::ObjectType.define do
  interfaces [DeviceInterface]
end

Instance Attribute Summary

Attributes inherited from BaseType

#description, #name

Instance Method Summary collapse

Methods inherited from BaseType

#==, #coerce_input, #connection_type, #define_connection, #define_edge, #edge_type, resolve_related_type, #resolve_type, #to_list_type, #to_non_null_type, #to_s, #unwrap, #valid_input?, #validate_input

Methods included from Define::InstanceDefinable

#define, #definition_proc=, #metadata

Methods included from Define::NonNullWithBang

#!

Constructor Details

#initializeInterfaceType

Returns a new instance of InterfaceType


29
30
31
# File 'lib/graphql/interface_type.rb', line 29

def initialize
  @fields = {}
end

Instance Method Details

#all_fieldsArray<GraphQL::Field>

Returns All fields on this type

Returns:


43
44
45
# File 'lib/graphql/interface_type.rb', line 43

def all_fields
  fields.values
end

#get_field(field_name) ⇒ GraphQL::Field

Returns The defined field for field_name

Returns:


38
39
40
# File 'lib/graphql/interface_type.rb', line 38

def get_field(field_name)
  fields[field_name]
end

#kindObject


33
34
35
# File 'lib/graphql/interface_type.rb', line 33

def kind
  GraphQL::TypeKinds::INTERFACE
end