Skip to content

Instantly share code, notes, and snippets.

@ramyak-mehra
Last active May 12, 2021 22:40
Show Gist options
  • Select an option

  • Save ramyak-mehra/b345cf9f67092fe2b06eee2a7198784e to your computer and use it in GitHub Desktop.

Select an option

Save ramyak-mehra/b345cf9f67092fe2b06eee2a7198784e to your computer and use it in GitHub Desktop.
Future<FetchPokemons$Query> _fetchArtemisClient(ArtemisClient client) async {
final pokemonsQuery =
FetchPokemonsQuery(variables: FetchPokemonsArguments(quantity: 15));
final result = await client.execute(pokemonsQuery);
if (result.hasErrors) {
throw Exception(result.errors);
}
return result.data!;
}
//If you are using something like graphql for client you can do something like this.
Future<FetchPokemons$Query> _fetchGraphqlClient(GraphQLClient client) async {
final pokemonsQuery =
FetchPokemonsQuery(variables: FetchPokemonsArguments(quantity: 20));
final queryOptions = QueryOptions(
document: pokemonsQuery.document,
variables: pokemonsQuery.variables.toJson(),
fetchPolicy: FetchPolicy.cacheAndNetwork);
final result = await client.query(queryOptions);
if (result.hasException) {
throw result.exception!;
}
return FetchPokemons$Query.fromJson(result.data!);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment