Flutter GraphQL Hooks 🪝

Watch on GitHub Star on GitHub Tweet!

Introduction

This package exposes an apollo-like set of hooks to be used with flutter, it's meant to be used together with the graphql_flutter package and it's based on it's latest implementation.

It can be used along with artemis to provide strongly typed hooks, example:

final query = GetRoomsQuery(variables: GetRoomsArguments(limit: 10, offset: 0));

final rooms = useQuery(QueryOptions(
  document: query.document,
  variables: query.getVariablesMap(),
));

final loading = rooms.result.loading;
final error = rooms.result.error;
final data = query.parse(rooms.result.data);
// Data will no longer be a [Map<String, dynamic>] and will have proper typings! 

Installing

dependencies:
  flutter_graphql_hooks:

Notes

In order to use the hooks, a GraphqlProvider must exist on the build context. Otherwise you'll need to manually pass the client in the hook as a parameter like:

final rooms = useQuery(QueryOptions(
  document: query.document,
  variables: query.getVariablesMap(),
), client: myGraphqlClient);

Libraries

flutter_graphql_hooks
graphql_hook_result
mutation_options_extensions
query_options_extensions
use_lazy_query
use_mutation
use_mutation_hook_result
use_query
use_query_hook_result
use_subscription