First, depend on this package:
And then import it inside your dart code:
Find the migration from version 3 to version 4 here.
To connect to a GraphQL Server, we first need to create a GraphQLClient. A GraphQLClient requires both a cache and a link to be initialized.
In our example below, we will be using the Github Public API. we are going to use HttpLink which we will concatenate with AuthLink so as to attach our github access token. For the cache, we are going to use GraphQLCache.
Always remember to replace
API_SECRET with the correct value that you copied from apito console.
Go to this page if you do not know where to find your api secrets for your project
In order to use the client, your
Mutation widgets must be wrapped with the
We recommend wrapping your MaterialApp with the GraphQLProvider widget.
Creating a query is as simple as creating a multiline string:
In your widget:
Again first create a mutation string:
The syntax for mutations is fairly similar to that of a query. The only difference is that the first argument of the builder function is a mutation function. Just call it to trigger the mutations (Yeah we deliberately stole this from react-apollo.)
For more detailed guide be sure to check out the official guide of the
graphql_flutter page here