Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/opencomponents/oc-graphql-client
OpenComponents Apollo client plugin for GraphQL
https://github.com/opencomponents/oc-graphql-client
graphql oc-plugin opencomponents
Last synced: 8 days ago
JSON representation
OpenComponents Apollo client plugin for GraphQL
- Host: GitHub
- URL: https://github.com/opencomponents/oc-graphql-client
- Owner: opencomponents
- License: mit
- Created: 2017-02-17T12:49:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-02T04:57:27.000Z (over 4 years ago)
- Last Synced: 2024-05-28T13:21:25.911Z (7 months ago)
- Topics: graphql, oc-plugin, opencomponents
- Language: JavaScript
- Size: 52.7 KB
- Stars: 10
- Watchers: 22
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-oc - GraphQL plugin - Plugin for integrating GraphQL (Registry Plugins/Utilities)
README
oc-graphql-client [![Build Status](https://travis-ci.org/opencomponents/oc-graphql-client.svg?branch=master)](https://travis-ci.org/opencomponents/oc-graphql-client)
==========## 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](https://github.com/opentable/oc) plugin that expose the a graphql client for interacting with a GraphQL based server.
## Requirements:
- OC Registry
- GraphQL Server
- Node >= v6## Install
````javascript
yarn add oc-graphql-client
````## Registry setup
More info about integrating OC plugins: [here](https://github.com/opentable/oc/wiki/Registry#plugins)
````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);
````## Register API
|parameter|type|mandatory|description|
|---------|----|---------|-----------|
|serverUrl|`string`|yes|The Url for the GraphQL server|## Usage
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 => { ... })
````## API
|parameter|type|mandatory|description|
|---------|----|---------|-----------|
|options|`object`|yes|A composite of the query & variables to pass to GraphQL server|
|headers|`object`|no|The headers to pass down to unerlying services|
|timeout|`int`|no|The timeout in ms. It defaults to OS default |## Contributing
PR's are welcome!
## License
MIT