1.1.3 • Published 5 years ago
gery v1.1.3
Gery
A light weight GraphQL GraphQLClient
Installation
yarn add gery
Quick start
import { query } from 'graphql-request'
import { gql } from 'gql-tag' // editor helper
const GET_PERSONS = gql`
{
allPersons {
id
name
}
}
`
const endpoint = 'https://api.graph.cool/simple/v1/swapi'
query(endpoint, GET_PERSONS).then(data => console.log(data))
Use Client
import { GraphQLClient } from 'gery'
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',
})
GraphQLClient.query(GET_PERSONS).then(data => console.log(data))
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',
})