Module: GraphQL::Execution::Typecast
- Defined in:
- lib/graphql/execution/typecast.rb
Overview
GraphQL object {value, current_type}
can be cast to potential_type
when:
current_type == potential_type
current_type
is a union and it containspotential_type
potential_type
is a union and it containscurrent_type
current_type
is an interface andpotential_type
implements itpotential_type
is an interface andcurrent_type
implements it
Class Method Summary collapse
-
.compatible?(current_type, potential_type, query_ctx) ⇒ Boolean
While
value
is exposed by GraphQL as an instance ofcurrent_type
, should it also be treated as an instance ofpotential_type
?.
Class Method Details
.compatible?(current_type, potential_type, query_ctx) ⇒ Boolean
While value
is exposed by GraphQL as an instance of current_type
,
should it also be treated as an instance of potential_type
?
This is used for checking whether fragments apply to an object.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/graphql/execution/typecast.rb', line 20 def self.compatible?(current_type, potential_type, query_ctx) if current_type == potential_type true elsif current_type.kind.union? current_type.possible_types.include?(potential_type) elsif potential_type.kind.union? potential_type.include?(current_type) elsif current_type.kind.interface? && potential_type.kind.object? potential_type.interfaces.include?(current_type) elsif potential_type.kind.interface? && current_type.kind.object? current_type.interfaces.include?(potential_type) else false end end |