@boter/graphql-client
TypeScript icon, indicating that this package has built-in type declarations

0.8.0 • Public • Published

@boter/graphql-client

A light weight GraphQL GraphQLClient

Installation

npm i @boter/graphql-client

Quick start

import { query } from '@boter/graphql-client'
import gql from 'gql-tag' // editor helper

const GET_PERSONS = gql`
  {
    allPersons {
      id
      name
    }
  }
`

const endpoint = 'https://api.graph.cool/simple/v1/swapi'

const data = await query(endpoint, GET_PERSONS)

Use Client

import { GraphQLClient } from '@boter/graphql-client'
import { gql } from 'gql-tag' // editor helper

const GET_PERSONS = gql`
  {
    allPersons {
      id
      name
    }
  }
`
const GraphQLClient = new GraphQLClient({
  endpoint: 'https://api.graph.cool/simple/v1/swapi',
})

const data = await GraphQLClient.query(GET_PERSONS)

Variables

const GET_PERSON = gql`
  query getPerson($id: ID) {
    Person(id: $id) {
      id
      name
    }
  }
`

const data = await query(endpoint, GET_PERSON, {
  id: 'cj0nv9peiewhf013011i9a4h2',
})

Typescript

interface Person {
  Person: {
    id: string
    name: string
  }
}

const GET_PERSON = gql`
  query getPerson($id: ID) {
    Person(id: $id) {
      id
      name
    }
  }
`

const data = await query<Person>(endpoint, GET_PERSON, {
  id: 'cj0nv9peiewhf013011i9a4h2',
})

License

MIT License

Readme

Keywords

none

Package Sidebar

Install

npm i @boter/graphql-client

Weekly Downloads

2

Version

0.8.0

License

MIT

Unpacked Size

16.5 kB

Total Files

11

Last publish

Collaborators

  • forsigner