Installation
Install the package
sh
npm install gazaniash
pnpm install gazaniash
yarn add gazaniash
bun install gazaniaRequirements
- Node.js >= 20.0.0
- TypeScript >= 5.0 (recommended)
Generate schema types
Gazania needs TypeScript types generated from your GraphQL schema. Use the CLI:
sh
npx gazania generate --schema https://api.example.com/graphql --output src/schema.tsOr from a local schema file:
sh
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.
Basic setup
Import the generated types and pass them to createGazania:
ts
import type { Schema } from './schema'
import { createGazania } from 'gazania'
const gazania = createGazania({} as Schema)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
Named schema registration
You can register schemas by name using module augmentation. The generated schema file can register itself:
ts
// In your generated schema file
declare module 'gazania' {
interface Schemas {
'https://api.example.com/graphql': Schema
}
}Then use the schema by URL:
ts
import { createGazania } from 'gazania'
const gazania = createGazania('https://api.example.com/graphql')