module GraphQL::Execution::Typecast

def self.compatible?(current_type, potential_type, query_ctx)

Returns:
  • (Boolean) - true if `value` be evaluated as a `potential_type`

Parameters:
  • the (GraphQL::Query::Context) -- context for the current query
  • can (GraphQL::BaseType) -- `value` be exposed using this type?
  • the (GraphQL::BaseType) -- type which GraphQL is using for `value` now
  • the (Object) -- value which GraphQL is currently exposing
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