0.6.0 • Published 3 years ago

@peajs/graphql-client v0.6.0

Weekly downloads
17
License
MIT
Repository
-
Last release
3 years ago

@peajs/graphql-client

A light weight GraphQL GraphQLClient

Installation

npm i @peajs/graphql-client

Quick start

import { query } from '@peajs/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 '@peajs/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