Callsheet
Reference

Codegen Config

Options for callsheet.config.ts and the codegen CLI.

Config shape

The config file exports a defineConfig(...) call with three top-level fields:

callsheet.config.ts
import { defineConfig } from '@callsheet/codegen';

export default defineConfig({
  sources: {
    graphql: [
      /* ... */
    ],
    tsRest: [
      /* ... */
    ],
  },
  output: {
    file: './src/generated/calls.ts',
  },
  overrides: [
    /* ... */
  ],
});
FieldRequiredDescription
sourcesYesWhere Callsheet discovers typed operations
outputYesWhere the generated module is written
overridesNoOverride the shape of generated entries

sources.graphql

Each entry in sources.graphql tells Callsheet where to find GraphQL document exports.

graphql: [
  {
    rootDir: './src/graphql',
    tsconfigFile: './tsconfig.json',
    entries: ['generated.ts'],
  },
],
FieldRequiredDescription
rootDirYesRoot directory for entry / namespace resolution
tsconfigFileYesTypeScript config used for module resolution and exports
entriesYesFile paths or glob patterns relative to rootDir
excludeNoGlob patterns relative to rootDir to exclude from entry matches
exportSuffixNoSuffix used to identify GraphQL document exports. Defaults to Document
pathPrefixNoPrefix added to all discovered entries from this source

Callsheet entries can be specific files or globs like **/*.ts. Exports matching the exportSuffix are treated as GraphQL documents.

sources.tsRest

Each entry in sources.tsRest points Callsheet at a ts-rest contract export.

tsRest: [
  {
    importFrom: './src/rest/contract',
    exportName: 'contract',
    pathPrefix: ['rest'],
  },
],
FieldRequiredDescription
importFromYesPath to the module that exports the contract
exportNameYesName of the contract export in that module
pathPrefixNoPrefix added to all discovered routes from this source

Callsheet walks the contract and infers whether each route is a query or mutation based on the ts-rest route definition.

output

Config for the generated calls module.

output: {
  file: './src/generated/calls.ts',
  exportName: 'calls',
  importFrom: '@callsheet/react-query',
},
FieldRequiredDescription
fileYesOutput file path for the generated module
exportNameNoName of the exported calls object. Defaults to calls
importFromNoPackage the generated module imports Callsheet builders from. Defaults to @callsheet/react-query

overrides

Overrides let you reshape generated entries when default discovery doesn't match the tree structure you want.

overrides: [
  {
    path: ['featuredFilms'],
    as: ['films', 'featured'],
    kind: 'query',
    options: {
      from: '../callsheet-options/films',
      name: 'featuredFilmsOptions',
    },
  },
],
FieldRequiredDescription
pathYesThe generated path to target
asNoMove the entry to a different path in the final tree
kindNoForce query or mutation when discovery can't infer it
optionsNoImport call options (like family or invalidates) from another module
entryNoNarrow the override to a specific source entry when multiple entries share the same path

options takes an object with from (module path) and name (export name). The referenced module should export a call options object that gets passed as the second argument to the builder.

Use entry when multiple generated entries share the same path and the override should only apply to one of them.

When overrides are useful

  • Renaming: Use as when a generated path like featuredFilms should live at films.featured in the tree.
  • Forcing kind: Use kind when a GraphQL document doesn't have enough information for Callsheet to tell whether it's a query or mutation.
  • Attaching options: Use options when a generated call should include shared defaults like family, staleTime, or invalidates that live in a separate module.

Running codegen

Callsheet can automatically build itself using the callsheet-codegen CLI. It reads your config and writes a generated module.

pnpm callsheet-codegen --config callsheet.config.ts

If the config file is named callsheet.config.ts and lives at the project root, the --config flag is optional.

FlagDescription
-c, --config <path>Path to the config file
-h, --helpShow help output

On this page