Small NodeJS Wrapper around apollo-client that provides easy access to running queries, mutations and subscriptions.
Install dependency:
yarn add kikstart-graphql-client graphql
Import GraphQLClient
:
import { GraphQLClient } from 'kikstart-graphql-client';
Create instance:
const client = new GraphQLClient({
uri: 'http://localhost:4000/graphql',
wsUri: 'ws://localhost:4000/graphql',
})
Run Query:
async getStatus() {
const { data, error } = await this.client.runQuery(`
query { status }
`);
if (error) {
throw error
}
return data.status
}
Run Subscription:
client.runSubscription(query)
.subscribe({
next: res => console.log(JSON.stringify(res.data.statusSubscription, null, 2)),
error: error => console.error(error),
complete: () => console.log('done'),
})
}
- Uses code from graphcurl.
- Based on npm-typescript-package-boilerplate