4.0.2 • Published 4 years ago

oc-graphql-client v4.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

oc-graphql-client Build Status

NOTICE!

  • The current released version (3.*) does not use the Apollo client due to memory consumption issues.
  • The client does not expose a querybuilder, instead just use a raw string as the examples does.

A OpenComponents plugin that expose the a graphql client for interacting with a GraphQL based server.

Requirements:

  • OC Registry
  • GraphQL Server
  • Node >= v6

Install

yarn add oc-graphql-client

Registry setup

More info about integrating OC plugins: here

...
var registry = new oc.registry(configuration);

registry.register({
  name: 'graphqlClient',
  register: require('oc-graphql-client'),
  options: {
    serverUrl: 'http://graphql-server.hosts.com'
  }
}, function(err){
  if(err){
    console.log('plugin initialisation failed:', err);
  } else {
    console.log('graphql client now available');
  }
});

...

registry.start(callback);

Register API

parametertypemandatorydescription
serverUrlstringyesThe Url for the GraphQL server

Usage

Example for a components' server.js:

module.exports.data = function(context, callback){
  const query = `
  query restaurantInfo($id: Int!) {
      restaurant(id: $id) {
        name
    }
  }`;

  const headers = {
    'accept-language': 'en-US, en'
  };

  context.plugins.graphql.query({ query, variables: { id: 4 } }, headers, timeout)
    .then(res => { ... })
    .catch(err => { ... })

API

parametertypemandatorydescription
optionsobjectyesA composite of the query & variables to pass to GraphQL server
headersobjectnoThe headers to pass down to unerlying services
timeoutintnoThe timeout in ms. It defaults to OS default

Contributing

PR's are welcome!

License

MIT

4.0.2

4 years ago

4.0.1

5 years ago

4.0.0

6 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago