This package is forked version from genql
It has been updated, fixed few bugs, actively adding features and updated dependencies and codebase to the latest packages
Read the quick start guide to generate a client locally
- Type completion
- Type validation
- Easily fetch all fields in a type
- Support subscription ( ws, graphql-ws, observable, etc )
- Built in file upload support
- Graphql Client built in
- Works with any client
- Works in node and the browser
- Built in Axios Client, and exported to extend with interceptors.
- Client Operation support for Axios configuration, such as headers, timeout, cancelToken, abortSignal, etc.
- Support batching queries
- Consistent response format { data, errors, extensions }
Find more server-client examples in the examples repo You will find multiple examples with different tools of building schema, query, mutation, websocket subscriptions and more.
First generate your client executing
npm i -D @gqlts/cli # cli to generate the client code
npm i @gqlts/runtime graphql # runtime dependencies
gqlts --schema ./schema.graphql --output ./generatedThen you can use your client as follows
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
}
}
}This repo contains two published packages:
@gqlts/cli: reads a GraphQL schema and generates the typed client files.@gqlts/runtime: powers generated clients at runtime for queries, mutations, subscriptions, batching, uploads, and custom fetchers.
Generated clients normally contain:
schema.graphql: schema snapshot used for generation.schema.ts: generated schema, request, response, and guard types.index.js/index.esm.js: generated CommonJS and ESM client entrypoints.index.d.ts: generated public TypeScript declarations.types.cjs.js/types.esm.js: compressed runtime type map.guards.cjs.js/guards.esm.js: generated runtime type guards.
Install from the repo root with Yarn classic:
yarn install --frozen-lockfileCommon commands:
yarn buildall
yarn test
yarn tscall
yarn --cwd website build
./demo-apps/build-and-test.shRun ./demo-apps/build-and-test.sh before pushing generator, runtime, upload, subscription, SDK, or Next.js changes. It runs the backend demo, SDK generation, standalone browser bundle, Next.js dev and production tests, and integration tests.
More details are in DEVELOPMENT.md.
Gqlts uses Changesets for coordinated releases of @gqlts/cli and @gqlts/runtime.
developpublishes prereleases likex.y.z-beta.nto npmbeta.masterpublishes stable releases likex.y.zto npmlatest.- both published packages are intentionally version-locked and release together.
Useful commands:
yarn changeset
yarn release:version:beta
yarn release:version:stable
yarn release:publish
yarn release:verifyNormal flow:
- Add a changeset in the same PR as runtime or CLI changes.
- Merge to
developto open or update the beta release PR. - Merge to
masterto open or update the stable release PR.
If a publish partially fails, use the Release Recovery GitHub Actions workflow to rerun publish for a specific ref, repair beta or latest dist-tags, and optionally remove the legacy develop dist-tag.
This is licensed under an MIT License. See details
