Generate the client
From http endpoint with --endpoint
gqlts --endpoint https://countries.trevorblades.com --output ./generatedYou can fetch using get passing the --get flag
gqlts --get --endpoint https://countries.trevorblades.com --output ./generatedFrom local schema with --schema
gqlts --schema ./schema.graphql --output ./generatedPassing headers with -H
gqlts -H 'Authorization: Bearer myToken' -e https://countries.trevorblades.com -o ./generatedOnly generate ES modules with --esm
If you are using nodejs you probably don't care about this flag
By default gqlts generates commonjs code that use require and module.exports to handle imports and exports
If you are compiling your code trough a bundler like webpack you can add the --esm flag to generate ES modules exports and imports, this way when you do import { createClient } from './generated' you are actually importing from an es module
Using ES modules has the advantage of smaller bundle size via tree shaking.
gqlts --esm --schema ./schema.graphql --output ./generatedGenerate both commonjs and ESM with --esm-and-cjs
If you publish a package with gqlts code you probably want to include both ESM and CJS code for users using browser and nodes respectively
To do that pass the --esm-and-cjs flag
gqlts --esm-and-cjs --schema ./schema.graphql --output ./generatedChanging scalar types with -S
This is useful if you want to map from a custom scalar to a type like string, number, etc.
By default custom scalars have type any
gqlts -S MyScalar:string -S AnotherScalar:number -e https://countries.trevorblades.com -o ./generatedSort generated code with --sort
If you see a lot of diffs between one generation and another you can use the --sort flag to sort object properties
The order of generated object properties is taken from the schema introspection by default, so you shouldn't need this flag if using popular frameworks like Apollo server
gqlts --sort -e https://countries.trevorblades.com -o ./generated