noverby / garph-gqty

A tRPC-style client for Garph

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@garph/gqty

tRPC-style client for Garph, based on GQty

npm i @garph/gqty

Example:

import { g } from 'garph'
import { InferClient, createClient } from '@garph/gqty'

export const queryType = g.type('Query', {
  greet: g.string()
    .args({
      name: g.string().optional().default('Max'),
    })
    .description('Greets a person')
})

type ClientTypes = InferClient<{ query: typeof queryType }>

export const { useQuery } = createClient<ClientTypes>({
  schema: g,
  url: 'http://localhost:4000/graphql'
})

Using the client (React):

import { useQuery } from './client'

export default function Example() {
  const query = useQuery()
  return <p>{ query.greet({ name: 'Mish' }) }</p>
}

Acknowledgements

  • tRPC for inspiration
  • Vicary of GQty project for early feedback and helping to make @garph/gqty possible

About

A tRPC-style client for Garph

License:MIT License


Languages

Language:TypeScript 100.0%