Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

GraphQL · Function

printSchema

printSchema converts a GraphQL schema object into SDL text. The text can be published to a schema registry for governance automation.

How it works

printSchema converts a GraphQL schema object into SDL text. The resulting string can be submitted to a registry or used by tooling that consumes a schema definition.

Syntax

printSchema(schema)

Parameters

NameTypeDescription
schemaGraphQLSchemaThe GraphQL schema object to serialize as SDL.

Returns

A string containing the schema in GraphQL SDL form.

Key points

  • Import printSchema from the graphql package before using it.
  • The function’s returned string can be embedded in a JSON payload for schema publication.
  • A common automation use is sending printed SDL to a schema registry.
  • The schema argument is the value serialized by the function.

Common mistakes

  • The printed SDL is text suitable for publishing, but registry workflows may also require version metadata.

Example: Print a schema as SDL

import { buildSchema, printSchema } from "graphql";

const schema = buildSchema(`
  type Query {
    greeting: String!
  }
`);

console.log(printSchema(schema));

Builds a schema and prints its SDL representation.

When to use it

Registry publication

Publish the current API contract to a schema registry.

Automation

Generate SDL text for governance or CI workflows.

Schema artifacts

Create a human-readable schema artifact for tooling.

Interview questions

QWhat does printSchema do?

It produces the schema definition in GraphQL SDL form from a schema object. The printed result can then be sent to a schema registry or another SDL-based tool.

Follow-up: Why might a team publish this output? A registry can use the SDL as the service’s versioned schema representation.

QHow is printSchema used in a registry-publishing workflow?

Call it with the GraphQL schema as its argument, then use the returned string as the request body or file content. The official example passes that string to a registry’s schema-publish endpoint.

Follow-up: What additional information might accompany the SDL? The example includes a separate version value in the published JSON payload.

QWhy is printSchema useful for tooling?

It serializes the schema into SDL rather than executing a query or discovering data at runtime. This makes the output useful for automation and governance tooling.

Follow-up: What should be checked before publishing? Validate that the schema object represents the intended API and attach the correct release metadata.

  • GraphQL schema
  • schema registry
  • SDL
  • version metadata

Source: Tooling and Automation for Governance - GraphQL. Checked 2026-10-15.