Description
Right now I've plugged in the basic queryComplexity
validationRule but noticed that i'm getting many logs of complexity queries. It turns out that clients are sometimes sending me POST objects with entire schemas full of queries and only calling one via operationName
. I am therefore getting many scores logging, eventually i get NaN
s logged then eventually it's erroring out complaining that my variables
are missing in my query. For example
"{\"errors\":[{\"message\":\"Argument \\\"site\\\" of required type \\\"Site!\\\" was provided the variable \\\"$site\\\" which was not provided a runtime value.
When I take out the extra query
s in the incoming POST, I actually get a correct logged query complexity score and no error.
So one option I have working is to manually call getComplexity
which takes a query
- here i can filter out all queries except for the one matching operationName. However, this is pretty hard to do if there is a query
with a ... fragment.
I wonder if this is a feature we can have built into the module from the get go? Only score what the user is actually calling based on operationName
? thanks.
Activity
purpleD17 commentedon Oct 24, 2019
Wow, i actually found someone who solved this online:
https://github.com/MichalLytek/type-graphql/blob/v0.17.5/examples/query-complexity/index.ts#L31
Though it could still be built in to this module.
ivome commentedon Oct 25, 2019
Thanks for bringing this up @purpleD17
I'd happily add this to the library. Would you mind creating a PR for this? I think we could just add an optional option to pass the
operationName
to the complexity rule and then add the logic from the example that you found.purpleD17 commentedon Oct 25, 2019
Yeah I can create a pr but I'm new to this stuff so it's something I'll have to work on a bit when I have some free time. I'm going to https://summit.graphql.com/ so it's something I can try to work on when i'm there - good place to get in person help if I need it.
feat: support query by operationName, related slicknode#22
ivome commentedon Apr 17, 2020
This is now available in v0.5.0