| 12345678910111213141516171819202122232425 |
- # frozen_string_literal: true
- class PokemonTradeSchema < GraphQL::Schema
- mutation(Types::MutationType)
- query(Types::QueryType)
- def self.id_from_object(object, type_definition, _query_ctx)
- GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
- end
- def self.object_from_id(id, _query_ctx)
- type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
- Object.const_get(type_name).find(item_id)
- end
- def self.resolve_type(_type, obj, _ctx)
- case obj
- when Pokemon
- Types::PokemonType
- else
- Rails.logger.error("Unexpected object when resolving GraphQL type: #{obj}")
- raise APIError::BaseError, 'Unexpected object when resolving GraphQL type'
- end
- end
- end
|