graphql-dotnet / graphql-dotnet

GraphQL for .NET

Home Page:https://graphql-dotnet.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can we determine the depth and complexity?

mariusbancila opened this issue · comments

I am looking into configuring allowed complexity for GraphQL queries, but it's quite challenging to come up with some numbers out of the blue given that our system is quite complex. I was thinking of logging the depth and complexity of GraphQL queries for a while and then do some analysis on the data in order to get some reasonable numbers.

I didn't see anything in the documentation about accessing the results from the analysis done in the framework. Is this possible somehow?

For v7, you can write your own complexity analyzer class, deriving from ComplexityAnalyzer and override Analyzed to obtain the results. Use .AddComplexityAnalyzer<MyComplexityAnalyzer>() to register it within your Startup.cs instead of the usual registration.

Although this class is deprecated, similar functionality will be available in v8 by deriving from the v8 ComplexityValidationRule and overriding the Analyzed method there. As of now, the actual complexity analysis code has not changed and so the calculations will be the same as in v7.

That worked. Thank you for the help!