Class: GraphQL::InterfaceType
- 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.
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#orphan_types ⇒ Object
Returns the value of attribute orphan_types.
-
#resolve_type_proc ⇒ Object
Returns the value of attribute resolve_type_proc.
Attributes inherited from BaseType
#ast_node, #default_relay, #default_scalar, #description, #introspection, #name
Instance Method Summary collapse
-
#all_fields ⇒ Array<GraphQL::Field>
These fields don’t have instrumenation applied.
-
#get_field(field_name) ⇒ GraphQL::Field
The defined field for
field_name
. -
#get_possible_type(type_name, ctx) ⇒ GraphQL::ObjectType?
Get a possible type of this InterfaceType by type name.
-
#initialize ⇒ InterfaceType
constructor
A new instance of InterfaceType.
-
#initialize_copy(other) ⇒ Object
-
#kind ⇒ Object
-
#possible_type?(type, ctx) ⇒ Boolean
Check if a type is a possible type of this InterfaceType.
-
#resolve_type(value, ctx) ⇒ Object
-
#resolve_type=(resolve_type_callable) ⇒ Object
Methods inherited from BaseType
#==, #coerce_input, #coerce_isolated_input, #coerce_isolated_result, #coerce_result, #default_relay?, #default_scalar?, #introspection?, #list?, #non_null?, resolve_related_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 Relay::TypeExtensions
#connection_type, #define_connection, #define_edge, #edge_type
Methods included from Define::InstanceDefinable
Methods included from Define::NonNullWithBang
Constructor Details
#initialize ⇒ InterfaceType
Returns a new instance of InterfaceType
31 32 33 34 35 36 |
# File 'lib/graphql/interface_type.rb', line 31 def initialize super @fields = {} @orphan_types = [] @resolve_type_proc = nil end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields
28 29 30 |
# File 'lib/graphql/interface_type.rb', line 28 def fields @fields end |
#orphan_types ⇒ Object
Returns the value of attribute orphan_types
28 29 30 |
# File 'lib/graphql/interface_type.rb', line 28 def orphan_types @orphan_types end |
#resolve_type_proc ⇒ Object
Returns the value of attribute resolve_type_proc
28 29 30 |
# File 'lib/graphql/interface_type.rb', line 28 def resolve_type_proc @resolve_type_proc end |
Instance Method Details
#all_fields ⇒ Array<GraphQL::Field>
These fields don’t have instrumenation applied
64 65 66 |
# File 'lib/graphql/interface_type.rb', line 64 def all_fields fields.values end |
#get_field(field_name) ⇒ GraphQL::Field
Returns The defined field for field_name
57 58 59 |
# File 'lib/graphql/interface_type.rb', line 57 def get_field(field_name) fields[field_name] end |
#get_possible_type(type_name, ctx) ⇒ GraphQL::ObjectType?
Get a possible type of this GraphQL::InterfaceType by type name
72 73 74 75 |
# File 'lib/graphql/interface_type.rb', line 72 def get_possible_type(type_name, ctx) type = ctx.query.get_type(type_name) type if type && ctx.query.schema.possible_types(self).include?(type) end |
#initialize_copy(other) ⇒ Object
38 39 40 41 42 |
# File 'lib/graphql/interface_type.rb', line 38 def initialize_copy(other) super @fields = other.fields.dup @orphan_types = other.orphan_types.dup end |
#kind ⇒ Object
44 45 46 |
# File 'lib/graphql/interface_type.rb', line 44 def kind GraphQL::TypeKinds::INTERFACE end |
#possible_type?(type, ctx) ⇒ Boolean
Check if a type is a possible type of this GraphQL::InterfaceType
81 82 83 84 |
# File 'lib/graphql/interface_type.rb', line 81 def possible_type?(type, ctx) type_name = type.is_a?(String) ? type : type.graphql_name !get_possible_type(type_name, ctx).nil? end |
#resolve_type(value, ctx) ⇒ Object
48 49 50 |
# File 'lib/graphql/interface_type.rb', line 48 def resolve_type(value, ctx) ctx.query.resolve_type(self, value) end |
#resolve_type=(resolve_type_callable) ⇒ Object
52 53 54 |
# File 'lib/graphql/interface_type.rb', line 52 def resolve_type=(resolve_type_callable) @resolve_type_proc = resolve_type_callable end |