@financial-times/n-memb-gql-client

A tiny wrapper around the FT Membership GraphQL API

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@financial-times/n-memb-gql-client
2.2.42 years ago7 years agoMinified + gzip package size for @financial-times/n-memb-gql-client in KB

Readme

n-memb-gql-client CircleCI npm version
A tiny wrapper around the membership graph ql api, with some convenient methods.
const membQl = require('@financial-times/n-memb-gql-client');

membQl.canned('user-query', { userId: 'XYZ' })
	.then(res => {
		if (!res._ok) {
			// valid response but contains errors
		}
		// handle response
	})
	.catch(err => {
		// handle error
	});

Usage

Ensure MEMBQL_API_KEY_PROD and MEMBQL_API_ENDPOINT_PROD env variable is set.
By default queries will use production.
You must also set MEMBQL_API_KEY_TEST and MEMBQL_API_ENDPOINT_TEST if you wish to query using the test environment.
Further more you can set MEMBQL_API_KEY_MOCK and MEMBQL_API_ENDPOINT_MOCK if you wish to use a mock mode.

membQl.query(query, variables [, {testMode, mockMode, keepAlive, timeout}])

  • query (string) a raw graph ql query see below.

  • variables (object) contains the variables required for the query.

Options

  • testMode (boolean) default=false whether or not to use the test endpoint and api key.

  • mockMode (boolean) default=false whether or not to use the mock endpoint and api key.

  • keepAlive (boolean) default=true whether or not to keep the connection to the GraphQL API alive.

  • timeout (integer) default=5000 connection timeout cutoff, in ms.

  • overrideHost (string) (optional) an override host to use instead of MEMBQLAPIENDPOINT (remember to include protocol and correct path).

  • apiKeyHeaderName (string) (optional) an override header to use instead of x-api-key (e.g. ft-next-backend-key or ft-api-key).

membQl.canned(queryName, variables [, {testMode, mockMode, keepAlive, timeout}])

  • queryName (string) the canned query name see below.

  • variables (object) contains the variables required for the query.

Options

  • testMode (boolean) default=false whether or not to use the test endpoint and api key.

  • mockMode (boolean) default=false whether or not to use the mock endpoint and api key.

  • keepAlive (boolean) default=true whether or not to keep the connection to the GraphQL API alive.

  • timeout (integer) default=5000 connection timeout cutoff, in ms.

  • overrideHost (string) (optional) an override host to use instead of MEMBQLAPIENDPOINT (remember to include protocol and correct path).

  • apiKeyHeaderName (string) (optional) an override header to use instead of x-api-key (e.g. ft-next-backend-key or ft-api-key).

Canned queries

membQl.canned('user-query', { userId: 'XYZ' });

See docs on canned queries here. Query names can be found here.

Custom queries

const customQuery = `
	query($session: String!) {
		userBySession(session: $session) {
			access {
				isB2c
			}
		}
	}
`;
membQl.query(customQuery, { session: 'XYZ' });