Disable Graphql Introspection on .NET

99 Views Asked by At

I am trying to disable GraphQL Introspection in my project and not having much luck with specific framework I am using. Im using the graphql-dotnet library v3 Should i update to the lastest?(v7)

I tried creating a custom schema filter and returning false. I take the idea from this issue https://github.com/graphql-dotnet/graphql-dotnet/issues/2692

1

There are 1 best solutions below

1
Ariel Serato On

Debugging i realized that the query object that comes with the request give me the information of what Operation its running. So calling query.OperationName tells you if its Introspection, mutation or a simple query.

This implementation solved my problem:

if(query.OperationName == "IntrospectionQuery")
            {
                return StatusCode(500, new { Message = "You can't execute introspection queries." });
            }