OpenComponents client plugin for GraphQL
npm install oc-graphql-clientoc-graphql-client 
==========
----
A OpenComponents plugin that expose the a graphql client for interacting with a GraphQL based server.
```javascript``
yarn add oc-graphql-client
More info about integrating OC plugins: here
``javascript
...
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);
``
|parameter|type|mandatory|description|
|---------|----|---------|-----------|
|serverUrl|string|yes|The Url for the GraphQL server|
Example for a components' server.js:
``javascript
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 => { ... })
``
|parameter|type|mandatory|description|
|---------|----|---------|-----------|
|options|object|yes|A composite of the query & variables to pass to GraphQL server|object
|headers||no|The headers to pass down to unerlying services|int`|no|The timeout in ms. It defaults to OS default |
|timeout|
PR's are welcome!
MIT