Graphios
Easy-to-use Axios-based HTTP client for GraphQL API's. This library is more suitable for back-end interactions with GraphQL servers (not frontends/UI's). The Auto-pagination feature allows fetching of large amounts of data from paginated GraphQL API's without the need to write custom code.
Features:
- Simple API focused on GraphQL use case.
- Auto-pagination (Relay pattern only, such as Github API)
- Event listener for paginated requests
- Configurable retries (and retryDelay)
Installing
Using npm:
$ npm install graphios
Using yarn:
$ yarn add graphios
Configuration object (input)
Response object (output)
Examples
Performing a simple query:
; const query = `{ users { firstName email }}` // using promises // Using async/awaitasync { try const response = await console; catch error console; }
Performing a paginated query
For auto-pagination support, a $cursor
variable should be included in the query. The API server must follow the relay pagination pattern using nodes and edges. The paginated query is not required to be on the first level, but only one pagination query is allowed per request.
Example using an usable query for the Github API
// import graphiosEvents for pagination events; // A query variable $cursor is required.const query = ` query Repository($cursor:String){ organization(login:"microsoft"){ membersWithRole(first:100, after:$cursor){ edges { node { name } } pageInfo { endCursor hasNextPage } } } }` const headers = 'authorization': `Bearer 1234567SuperHardKey8910` // using promises // Using async/awaitasync { try const response = await console; catch error // If any page fails, it will end here console; } // Optional pagination event handlergraphiosEvents
Axios custom configuration (optional input)
An optional second object can be passed if any specific configuration from Axios is needed. This will override any configuration made on the graphios config (first parameter).
Example:
Credits
Relies on the excellent work provided by axios and axios-retry.