mnr-graphql-client
Opinionated wrapper around apollo-client
You may not need it!
This is a custom, highly opinionated solution aimed at code reuse for a few private projects. You'd be better off using Apollo Client directly.
Installation
$ npm install --save mnr-graphql-client
Usage example
const createGraphQLClient = ; const graphQLClient = ; // This is an Express endpoint handler { try const query = ; const variables1 = var: 'foo' ; const data1 = await graphQLClient; const mutation = ; const variables2 = var: 'bar' ; const data2 = await graphQLClient; catch err if errname === 'ServiceUnavailable' resstatus503; return; ; }
API Reference
createGraphQLClient(uri)
-
{String} uri
URI of the GraphQL server. -
Returns
{Object} graphQLClient
.
Creates a client object which exposes methods for querying GraphQL server.
graphQLClient.query(requestOptions, req)
-
{Object} requestOptions
Options to pass in Apollo's originalquery
method. -
{Object} req
Express'Request
object. -
Returns
{Promise<Object>}
Full original Apollo's response object. -
Throws
{ServiceUnavailable}
,BadGraphQLRequest
,UnexpectedError
.
Alias for Apollo's original query
method.
graphQLClient.mutate(requestOptions, req)
-
{Object} requestOptions
Options to pass in Apollo's originalmutate
method. -
{Object} req
Express'Request
object. -
Returns
{Promise<Object>}
Full original Apollo's response object. -
Throws
{ServiceUnavailable}
,BadGraphQLRequest
,UnexpectedError
.
Alias for Apollo's original mutate
method.