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 collapse

Attributes inherited from BaseType

#default_relay, #default_scalar, #description, #introspection, #name

Instance Method Summary collapse

Methods inherited from BaseType

#==, #coerce_input, #coerce_isolated_input, #coerce_isolated_result, #coerce_result, #connection_type, #default_relay?, #default_scalar?, #define_connection, #define_edge, #edge_type, #introspection?, resolve_related_type, #resolve_type, #to_definition, #to_list_type, #to_non_null_type, #to_s, #unwrap, #valid_input?, #valid_isolated_input?, #validate_input, #validate_isolated_input

Methods included from Define::InstanceDefinable

#define, #metadata, #redefine

Methods included from Define::NonNullWithBang

#!

Constructor Details

#initializeInterfaceType

Returns a new instance of InterfaceType.



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

def initialize
  super
  @fields = {}
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



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

def fields
  @fields
end

Instance Method Details

#all_fieldsArray<GraphQL::Field>

These fields don't have instrumenation applied

Returns:

See Also:

  • Get fields with instrumentation


53
54
55
# File 'lib/graphql/interface_type.rb', line 53

def all_fields
  fields.values
end

#get_field(field_name) ⇒ GraphQL::Field

Returns The defined field for field_name.

Returns:



46
47
48
# File 'lib/graphql/interface_type.rb', line 46

def get_field(field_name)
  fields[field_name]
end

#initialize_copy(other) ⇒ Object



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

def initialize_copy(other)
  super
  @fields = other.fields.dup
end

#kindObject



41
42
43
# File 'lib/graphql/interface_type.rb', line 41

def kind
  GraphQL::TypeKinds::INTERFACE
end