Visualizing the GraphQL schema
When the GraphQL API becomes more complex, it is difficult to understand the schema. We can use GraphQL Voyager
to visualize the GraphQL schema. GraphQL Voyager
is an open-source project that can visualize the GraphQL schema in an interactive graph. It is a frontend application that can be integrated with the GraphQL API. To use it in our ASP.NET Core application, we can use the GraphQL.Server.Ui.Voyager
package. This package is part of the GraphQL.NET project.
Follow these steps to use GraphQL Voyager in our application:
- Install the
GraphQL.Server.Ui.Voyager
package using the following command:dotnet add package GraphQL.Server.Ui.Voyager
- Add the following code to the
Program.cs
file:app.MapGraphQLVoyager();
The preceding code adds a middleware that maps the Voyager UI to the default URL
ui/voyager
. If you want to specify a different URL, you can pass the URL as a parameter, as in this example:app.MapGraphQLVoyager("/voyager");
...