At build time: export_schema_sdl
The primary path is a runtime helper that lives in
nestrs-graphql. It wraps
async-graphql’s built-in SDL printer (Schema::sdl()).
SDLExportOptions::default() .federation().compose_directive():
@link / @key directives and the
_Entity / _service plumbing an Apollo Router expects.
At runtime: nestrs-cli graphql sdl
For CI jobs that hit a running federation subgraph, the CLI ships
a thin exporter. It POSTs the standard federation introspection
query ({_service{sdl}}) and writes the response to disk.
--url <http>— required. The GraphQL endpoint.--out <path>— required. Output file. Parent directories are created automatically.--bearer-token <token>— optional. Adds anAuthorization: Bearer <token>header.--federation(default) — query{_service{sdl}}(Apollo Federation v2 introspection).--no-federation— query standard introspection instead.
When to use which
- Build-time (
export_sdl_to_file) — when you control the schema construction code. Use this in your binary’s startup or in a dedicatedbin/print_schema.rssocargo run --bin print_schemaregenerates SDL on every change. - Runtime (
nestrs-cli graphql sdl) — when you need SDL from a service you don’t own (a remote federation subgraph, a staging environment) or when you want to verify that the live schema still matches what you expected.
curl rather than pulling a Rust HTTP
client, so the CLI stays light. curl is on every macOS / Linux
dev box.
Programmatic access
The same parser the CLI uses (parse_sdl_body) is exposed for
embedding in custom tooling:
See also
mintlify-docs/guides/graphql-websockets— the GraphQL HTTP surface.nestrs-graphql::federation— the federation gateway and the_service { sdl }field on the gateway itself.nestrs-graphql::SDLExportOptions— federation / formatting flags passed toexport_sdl_with_options_to_file.