Skip to main content
The schema is one SDL file. Download it once, point a code generator at it, and every query you write gets types checked against the API.

Download the schema

Either route gives the same SDL for hosted Darpan. From the live API. GET /rest/s1/graphql/sdl needs no key. It returns JSON with the SDL in one string field, sdl, so unwrap it:
A self-hosted instance serves the same path on its own backend URL. This is the schema the server is running now. From GitHub. The schema these docs are generated from is committed as graphql-reference/schema.graphql:
It is updated when the docs are regenerated, so it can trail a deploy by a short while. Use the live route when the two must match exactly.
Introspection (__schema, __type) is a query like any other: send it to /graphql/public with an API key. Without one it returns UNAUTHENTICATED. Only /graphql/sdl is open.

Generate a typed TypeScript client

This uses GraphQL Code Generator with its client preset.
  1. Install it next to your code:
  2. Save schema.graphql in the project root, and add codegen.ts:
    codegen.ts
  3. Write each query in its own .graphql file under src/:
    src/morning.graphql
  4. Generate:
    src/gql/graphql.ts now holds MorningDocument, MorningQuery and MorningQueryVariables. Run it again whenever you change a query or download a new schema.
  5. Call the API with the generated types:
    src/morning.ts
    Run it with npx tsx src/morning.ts, or build it with your usual bundler. A misspelt field or a missing $audit now fails at generate or compile time, not in production.

Pitfalls