I completed watching some movies on tips on how to use GraphQL in iOS. I am attempting to apply writing queries and I assumed possibly I’d use PokeAPI GraphQL. Now I wrote a question that fetches a single Pokemon with the next: id, identify, order, varieties & sprites. Now the question works if I do not add the sprites. Additionally the sprites sort is jsonb! do not actually know what that is however was ready to make use of it to get the data I needed from the sprites. Right here is how the question appears like.
question GetAllPokemon {
Checklist: pokemon_v2_pokemon(
order_by: [{ pokemon_species_id: asc, id: asc }],
restrict: 1
) {
id
identify
order
varieties: pokemon_v2_pokemontypes {
slot
sort: pokemon_v2_type {
identify
}
}
sprites: pokemon_v2_pokemonsprites {
dwelling: sprites(path: "different.dwelling")
showdown: sprites(path: "different.showdown")
official: sprites(path: "different.official-artwork")
}
}
}
Now I added this to my mission and utilizing this methodology to name the question identical to the tutorials I’ve watched. The tutorials did not have this jsonb!. Now that is how I am calling it in Xcode.
Community.shared.apollo.fetch(question: GetAllPokemonQuery()) { lead to
swap outcome {
case .success(let response):
print(response)
case .failure(let error):
print(error)
}
}
Now that is at all times falling I do not know why however I’ve a sense it is due to the sprites:jsonb!. The sprites have nested objects that may be nil. That is the error I am getting.
GraphQLExecutionError(path: Checklist.0.sprites.0.dwelling, underlying: ApolloAPI.JSONDecodingError.couldNotConvert(worth: AnyHashable([AnyHashable(“front_default”): AnyHashable(“https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/home/1.png”), AnyHashable(“front_female”): AnyHashable(<null>), AnyHashable(“front_shiny”): AnyHashable(“https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/home/shiny/1.png”), AnyHashable(“front_shiny_female”): AnyHashable(<null>)]), to: Swift.String))
Now I am fully misplaced and been caught right here for a few hours. Can somebody level me in the proper route on how I’d have the ability to get this to work. Is also it potential to have the ability to go in an empty string as a substitute of null?
Hope that I’d to have the ability to fetch no less than one Pokemon utilizing GraphQL