graphql-validation-complexity
graphql-validation-complexity copied to clipboard
add support for calculating cost based on args
I tried to add that to this package here but ended up building my own validator that has support for args, variables and custom settings per field, similar to the implementation of the sangria library: https://github.com/ivome/graphql-query-complexity
neat!
With Apollo Server, creating a new validation rule per request is tricky. In general, it's also not easy to get the relevant variables for a batch request.
I'm going to instead build this as a per-request (in batch) extension that sets variables onto a singleton before and after the validation phase.
This should be okay, given that validation is synchronous anyway.