Kikstart Graphql Client Save

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

Project README

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

Open Source Agenda is not affiliated with "Kikstart Graphql Client" Project. README Source: beeman/kikstart-graphql-client

Open Source Agenda Badge

Open Source Agenda Rating