Redux Offline Apollo Link
NOTE This is still TBD. Use at your own risk!!
This is a close fork of apollo-upload-client, and acts as a drop in replacement.
I needed a way to get customized actions dispatched from apollo as network activity occured (request, success, failures).
This is closely tied with Redux Offline.
Redux Offline offers actions to be dispatched when a device is offline and go to a queue (aka outbox).
Requirements
@redux-offline/redux-offline: ^2.0.0
apollo-client: ^2.4.8
Installation
;;; const client = link: ApolloLink cache: ;
Usage in Components
In order to use the redux actions, you need to provide a variables.[VARIABLE NAME]
to your graphql
higher order component call.
The only REQUIRED variable to date is actionType
Options
uri
- The GraphQL URIfetch
- Description NeededfetchOptions
- Description Neededcredentials
- Description Neededheaders
- Description NeededincludeExtensions
- Description NeededglobalErrorsCheck
: An Optional function to be called whenever a graphql result containserrors
. Callback function contains aresult
parameter, which contains 2 keys,errors
anddata
onCatchErrors
: An Optional function to be called during acatch
from thefetch
call. Callback function contains a singleerror
parameter which contains theError
Variables
actionType
REQUIRED - The name of the request actionactionCommitSuffix
- Suffix of the action type when a success occurs Default: "COMMIT"actionRollbackSuffix
- Suffix of the action type when a rollback occurs Default: "ROLLBACK"options
- Suffix of the action type when a rollback occurs Default: "ROLLBACK" -payloadFormatter(payload)
Optional Function to format the response coming back from GraphQL on a successful retrieval.payload
is provided as a parameter. This function returns back the modified data. This is a good place to run data normalizationserrorsCheck(result)
Optional Function to give the client the choice for whether it should throw an error if errors are present on GraphQL response. It throws an error by default if function is not provided. If you want to not call the_COMMIT
or_ROLLBACK
throw anew AbortEffectsError()
.parseAndHandleHttpResponse(operation, result)
Optional Function to give the client the choice for whether it should throw an error if there's an HTTP/GraphQL schema error present on GraphQL response. It throws an error by default if the function is not provided.skipOffline
Skips offline check returning error right away if connection can't be stablished.
Examples
graphql Query HoC Example
DemoQuery;
graphql Mutation Example
Mutation;
Direct Client call Example
const client = thisprops;return client;