1.5.0 • Published 2 years ago

@aviosgroup/content-client v1.5.0

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
2 years ago

@avios/content-client

Client for accessing contentful data

Installation

This module is published to npm as a private module. You'll need a token to install it or be logged in to npm as a user who is a member of the npm aviosgroup organisation

Usage

The module is installed in both the front and backend as a normal npm module, installed via lerna (lerna add @aviosgroup/content-client)

Modules can be imported in the normal es6 way...

const { getFeatureToggles }, Content = require('@aviosgroup/content-client');

In order to use this package it must both the contentful api config set along with the cache client to be used to store the responses.

import { CBR } from '@aviosgroup/cbr-client';
const { GRAPHQL_URL, GRAPHQL_ACCESS_KEY } = publicRuntimeConfig;
  CBR.setGraphQLConfig({
  URL: GRAPHQL_URL,
  ACCESS_KEY: GRAPHQL_ACCESS_KEY,
});

Developing / Contributing

Running

When developing locally, use npm run start to have webpack compiling new versions on change

If linked in a Lerna environment you should not need to publish new versions to test the code in a project

Building

npm run build will build a production bundle

Publishing

When ready to release, its npm publish

Testing

There's two types of tests in cbr-client:

End-to-end

Mocking the response from the Hasura API using nock, you can see an example in test/merchants.test.js.

Query correctness assertion

We use graphql-tools and a copy of the Hasura schema (in test/support/schema.json) The example in test/merchants_query.test.js loads the schema and launches the query, if it is correct the library will return some default mock data.

It can be also used to return a specific mock. For more information check the official documentation here

If you need to refresh the Hasura schema you can use the Apollo client and then do a

apollo schema:download --endpoint https://staging.collection.and.avios.digital/v1/graphql --header 'X-Hasura-Admin-Secret: [HASURA_SECRET]'

this will create the schema.json file