pokemon_trade_schema.rb 746 B

123456789101112131415161718192021222324252627
  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
  18. .error("Unexpected object when resolving GraphQL type: #{obj}")
  19. raise APIError::BaseError, 'Unexpected object when resolving GraphQL type'
  20. end
  21. end
  22. end