Search code examples
asp.net-web-apigraphqlgraphiqlhotchocolate

Graphiql playground in a .Net Framework Web API


How do we implement a Graphql Playground in ASP.NET Framework Web Application? I was able to query using Postman's new GraphQL POST and it is working as expected. But I was not able to host the graphiql playground using HotChocolate's AspNet Classic GraphiQL nuget.

https://www.nuget.org/packages/HotChocolate.AspNetClassic.GraphiQL/

It would be really helpful if anyone can provide a code snippet or documentation specific to ASP.NET Framework.


Solution

  • All you have to do is add it to your startup.cs file:

     //Graph QL add to pipeline and use schemas
     // app.UseWebSockets()
        app.UseGraphQL("/graphql")
           .UsePlayground();
    

    You can also have it up automatically if you wanted to. Every time you hit debug, it will open the playground if you set the url in your project properties

    enter image description here