Skip to content

Type safe TypeScript client for any GraphQL API

License

Notifications You must be signed in to change notification settings

benjaminbradley/genql

 
 

Repository files navigation





Type safe Graphql query builder

Write Graphql queries with type validation and auto completion



Read the quick start guide to generate a client locally

🔥 Features

  • Type completion
  • Type validation
  • Easily fetch all fields in a type
  • Support subscription
  • Graphql Client built in
  • Works with any client
  • Works in node and the browser

Example

First generate your client executing

npm i -D @genql/cli # cli to generate the client code
npm i graphql @genql/runtime # runtime dependencies
genql --schema ./schema.graphql --output ./generated

Then you can use your client as follow

import { createClient, everything } from './generated'
const client = createClient()

client
    .query({
        countries: {
            name: true,
            code: true,
            nestedField: {
                ...everything, // same as __scalar: true
            },
        },
    })
    .then(console.log)

The code above will fetch the graphql query below

query {
    countries {
        name
        code
        nestedField {
            scalarField1
            scalarField2
        }
    }
}

Sponsors

Notaku

Notaku

Vercel


Licensed under MIT.

About

Type safe TypeScript client for any GraphQL API

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 95.4%
  • JavaScript 4.5%
  • CSS 0.1%