pokemon_trade_schema.rb 733 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class PokemonTradeSchema < GraphQL::Schema
  3. mutation(Types::MutationType)
  4. query(Types::QueryType)
  5. def self.id_from_object(object, type_definition, _query_ctx)
  6. GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
  7. end
  8. def self.object_from_id(id, _query_ctx)
  9. type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
  10. Object.const_get(type_name).find(item_id)
  11. end
  12. def self.resolve_type(_type, obj, _ctx)
  13. case obj
  14. when Pokemon
  15. Types::PokemonType
  16. else
  17. Rails.logger.error("Unexpected object when resolving GraphQL type: #{obj}")
  18. raise APIError::BaseError, 'Unexpected object when resolving GraphQL type'
  19. end
  20. end
  21. end