Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@genql/runtime

remorses10.1kISC2.10.0TypeScript support: included

Genql runtime client

readme





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 @genql/runtime graphql # 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

Vercel


Licensed under MIT.

changelog

2.9.0

Support for more than one : in -S option (by @boredland)

Fixed declaration files generations for enums (by @DanielRose)

2.8.0

Add as const on enum objects to not use type object values as strings

2.7.0

Added enumGraphqlEnumName exports to get access to enum strings

2.6.0

  • Query any interface on an union, not only the common ones
  • Fixed __typename always optional

2.5.0

  • Do not query falsy values when using __scalar

2.4.0

2.3.3

  • genql-cli package becomes @genql/cli
  • genql-runtime package becomes @genql/runtime
  • headers can be an async function
  • you can now add an operation name to a query using __name
  • only generate commonjs code by default (using require and module.exports) to prevent people from importing from index.esm, use the --esm flag if you want to use esm
  • response types only include requested fields
  • added built in batching (see https://genql.now.sh/docs/usage/batching-queries)
  • --sort flag
  • generated types.json now is types.js
  • smaller types.js and hence smaller bundle size
  • made the website page converter to convert from graphql queries to genql code: https://genql.now.sh/converter
  • custom fetcher now has type (operation: GraphqlOperation | GraphqlOperation[], ) => Promise<ExecutionResult> to support built in batching
  • added a @genql/cli/printer module to print a graphql query AST to genql code