https://github.com/txbm/graphql-http
A GraphQL client for executing queries over HTTP.
https://github.com/txbm/graphql-http
Last synced: 3 months ago
JSON representation
A GraphQL client for executing queries over HTTP.
- Host: GitHub
- URL: https://github.com/txbm/graphql-http
- Owner: txbm
- License: mit
- Created: 2016-05-06T21:11:31.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-04T19:37:20.000Z (about 9 years ago)
- Last Synced: 2025-06-14T11:02:57.050Z (12 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql-http
A GraphQL client for executing queries over HTTP.
### DISCLAIMER
This library is not suitable for production use. If you're looking for a client
with similar functionality, see [Lokka](https://github.com/kadirahq/lokka). It
has much more support and is much more robust.
### Usage
```js
import { GQLClient } from 'graphql-http';
const client = GQLClient('http://localhost:3000', {
fetch: {
// anything passed here is merged with
// the options passed to fetch()
credentials: true,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
}
});
```
Queries
```js
client.query(`
query ($id: RecordID!) {
user(id: $id) {
id
name
}
}
`, { id: 1234 }).then((result) => {
console.log(result.data.user);
// => { id: 1234, name: ... }
});
```
Mutations
```js
client.mutate(`
mutation ($id: RecordID!, $name: String!) {
updateUser(input: {id: $id, name: $name}) {
user {
id
name
}
}
}
`, { id: 1234, name: 'Danny' }).then((result) => {
console.log(result.data.user);
// => { id: 1234, name: 'Danny' }
});
```