https://github.com/frux/graphin
💧Javascript isomorphic GraphQL client
https://github.com/frux/graphin
Last synced: 4 months ago
JSON representation
💧Javascript isomorphic GraphQL client
- Host: GitHub
- URL: https://github.com/frux/graphin
- Owner: frux
- Created: 2016-07-26T08:22:42.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-27T14:03:03.000Z (over 9 years ago)
- Last Synced: 2025-07-07T12:49:20.724Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 41 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Graphin [](https://travis-ci.org/frux/graphin) [](https://github.com/sindresorhus/xo)
> Isomorphic JavaScript GraphQL client
```js
import Graphin from 'graphin';
const graphin = new Graphin('https://my.graphql.endpoint.com');
// Simple GraphQL query
graphin.query(`{
userList {
login
name
email
}
}`)
.then(data => {
console.log(data.userList);
});
// List of users cached for a minute
graphin.query(`{
photoList {
id
url
description
width
height
}
}`, {cache: 60000})
.then(data => {
console.log(data.photoList);
});
// Simple GraphQL mutation
graphin.query(`mutation {
updatePhoto(id: 100500, description: "Photo of a real Unicorn!") {
id
}
}`);
```
## API
### new Graphin(endpoint, options, fetcher) ⇒ ``Graphin``
| Param | Type | Description |
| --- | --- | --- |
| endpoint | ``string`` | GraphQL endpoint URL |
| options | ``object|undefined`` | Graphin general options. Affect all requests. Default {} |
| options.cache | ``number`` | Cache TTL in ms |
| options.fetch | ``object`` | Fetch options |
| options.verbose | ``boolean`` | Verbose mode. Default false |
| fetcher | ``function|undefined`` | Fetch function (url, options) => Promise. Default fetch |
-----------------
### graphin.query(url, options) ⇒ ``Promise``
Makes GraphQL Query
| Param | Type | Description |
| --- | --- | --- |
| url | ``string`` | GraphQL Query |
| requestOptions | ``object|undefined`` | Request options. Affect only this request. Merge with general options. Default {} |
| requestOptions.cache | ``number`` | Cache TTL in ms |
| requestOptions.fetch | ``object`` | Fetch options |
| requestOptions.verbose | ``boolean`` | Verbose mode. Default false |
-----------------
### graphin.getQueryURL(query) ⇒ ``string``
Converts GraphQL query to URL
| Param | Type | Description |
| --- | --- | --- |
| query | ``string`` | GraphQL Query |