graphqlrelayhotchocolate

How can I print the schema in HotChocolate as GraphQL SDL


It would be great for development with Relay to print the GraphQL SDL directly with the Hot Chocolate GraphQL server. Is there a way to do this?

schema {
  query: Query
}

type Query {
  sayHello: String
}

Solution

  • Hot Chocolate Server provides easy ways to print the schema as GraphQL SDL.

    1. You can print any schema by calling ToString on ISchema.

      This is a more programmatic way to do it, but never the less it can be quite useful to just print the schema in tests or console tools. Good to know here is that any syntax node will allow you to be printed that way. So, even if you want to print a parsed query, you can just do ToString on it to get its GraphQL language string representation.

    2. For things like Relay, it is quite useful to have the schema available on an endpoint to just download it. Hot Chocolate server provides in all versions a GraphQL SDL endpoint.

      Version 10 and earlier: http://localhost:5000/graphql/schema

      Version 11 and newer: http://localhost:5000/graphql?sdl

      This URL should be valid when hosting the GraphQL endpoint on the graphql route.