Installation
Install the package
npm install gazaniapnpm install gazaniayarn add gazaniabun install gazaniaRequirements
- Node.js >= 22.12.0
- TypeScript >= 5.0 (recommended)
Generate schema types
Gazania needs TypeScript types generated from your GraphQL schema. Use the CLI:
npx gazania generate --schema https://api.example.com/graphql --output src/schema.tsOr from a local schema file:
npx gazania generate --schema schema.graphql --output src/schema.tsThis writes a TypeScript file with all the type definitions from your schema. See Workflows for more on schema generation and configuration.
Do not commit the generated schema file
Add the output file to .gitignore. The format of generated schema files is not a stability guarantee — it may change in any Gazania release without a major version bump. Regenerate as part of your build or CI pipeline.
# .gitignore
src/schema.tsBasic setup
The generated schema file registers itself via module augmentation. After generating types, use the schema URL with createGazania:
import { createGazania } from 'gazania'
const gazania = createGazania('https://api.example.com/graphql')The gazania object gives you typed builders for GraphQL operations:
gazania.query(): queriesgazania.mutation(): mutationsgazania.subscription(): subscriptionsgazania.fragment(): named fragmentsgazania.partial(): reusable selection partialsgazania.enum(): typed enum values
Passing schema types directly
If you prefer not to use named schema registration, you can pass the schema type directly:
import type { Schema } from './schema'
import { createGazania } from 'gazania'
const gazania = createGazania({} as Schema)