Skip to content

๐Ÿš€ Small NodeJS Wrapper around apollo-client that provides easy access to running queries, mutations and subscriptions.

License

Notifications You must be signed in to change notification settings

beeman/kikstart-graphql-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

kikstart-graphql-client

Small NodeJS Wrapper around apollo-client that provides easy access to running queries, mutations and subscriptions.

GitHub code size in bytes GitHub repo size npm npm npm npm NPM npm GitHub last commit npm collaborators

Usage

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'),
   })
}

Credits

MIT License