Registry publication
Publish the current API contract to a schema registry.
GraphQL · Function
printSchema converts a GraphQL schema object into SDL text. The text can be published to a schema registry for governance automation.
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.
printSchema(schema)| Name | Type | Description |
|---|---|---|
schema | GraphQLSchema | The GraphQL schema object to serialize as SDL. |
A string containing the schema in GraphQL SDL form.
printSchema from the graphql package before using it.import { buildSchema, printSchema } from "graphql";
const schema = buildSchema(`
type Query {
greeting: String!
}
`);
console.log(printSchema(schema));Builds a schema and prints its SDL representation.
Publish the current API contract to a schema registry.
Generate SDL text for governance or CI workflows.
Create a human-readable schema artifact for tooling.
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.
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.
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 schemaschema registrySDLversion metadata