/// <summary>Returns a Pokemon batch</summary> /// <param name="names">The Pokemons names</param> public async Task <IEnumerable <Pokemon> > GetPokemonBatch(string[] names) { IQuery[] queries = names.Select(name => pokemonQuery(name)).ToArray(); using var client = new GraphQLClient(this.graphqlPokemonUrl); IReadOnlyDictionary <string, JToken> batch = await client.GetBatch(queries); return(batch.Values.Select(jToken => jToken.ToObject <Pokemon>())); }
public async Task TestGetBatch() { Func <string, IQuery <Pokemon> > query = (string name) => new Query <Pokemon>("pokemon") .Alias(name) .AddArguments(new { name }) .AddField(p => p.Name); using var client = new GraphQLClient(URL); IReadOnlyDictionary <string, JToken> batch = await client.GetBatch(new IQuery[] { query("Pikachu"), query("Bulbasaur") }); Pokemon pikachu = batch["Pikachu"].ToObject <Pokemon>(); Assert.NotNull(pikachu); Assert.Equal("Pikachu", pikachu.Name); Pokemon bulbasaur = batch["Bulbasaur"].ToObject <Pokemon>(); Assert.NotNull(bulbasaur); Assert.Equal("Bulbasaur", bulbasaur.Name); }