@aviosgroup/cbr-client v2.2.0
@avios/cbr-client
CBR Client is a module providing cbr graphql queries and a client to make the request
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/cbr-client)
Modules can be imported in the normal es6 way...
const { cbr, merchants } = require('@aviosgroup/cbr-client');
If using standalone queries such as the getFlexibleMerchantsQuery
from
the merchants module, no additional setup is required. In the estore
these are used with apollo graphql, where the fetch is handled by apollo
In the case of the estore backend however the fetch is done by the cbr client itself. In cases where you want to use cbr-client to do the fetch it requires config to be set;
import { CBR } from '@aviosgroup/cbr-client';
const { GRAPHQL_URL, GRAPHQL_ACCESS_KEY } = publicRuntimeConfig;
CBR.setGraphQLConfig({
URL: GRAPHQL_URL,
ACCESS_KEY: GRAPHQL_ACCESS_KEY,
});
@TODO - Split the fetch behaviour from all the queries so we can optionally pass
a flag to fetch the data in the cbr-client
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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago