-
Notifications
You must be signed in to change notification settings - Fork 41
Calculate query comlexity outside validation context #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Displaying the calculated complexity is already possible via the https://github.com/graphql/express-graphql#providing-extensions If you want to calculate the complexity independently from the query execution and validation, you could simply run the validation with only that rule. This could also be placed in resolvers etc. |
Yes, calculating the complexity independently from the query execution is what I'm looking for. I figured out a way to do this by invoking the validation function and returning a deferred promise from the That being said, I can't see |
That's just the default export being named that way in the test files...
Maybe it makes sense to build a helper function that is exported by this package. Something like this: function calculateComplexity(options: {
estimators: ComplexityEstimator[],
schema: GraphQLSchema,
query: DocumentNode,
variables?: ObjMap<mixed>
}): number; This could then be used in any context and would also allow to calculate the complexity of a partial query by passing any query node. I'd happily merge a PR for that |
This is now added as |
I was wondering if it's possible to calculate complexity based on the current query, statically. In an ideal situation we'd be able to pass a string containing a GraphQL query or an info object which would return the complexity for that query.
This way we would be able to display the cost of a query to the user similar to how GitHub does: https://developer.github.com/v4/guides/resource-limitations/#returning-a-calls-rate-limit-status.
I've tried fiddling around by manually invoking the nodeComplexity function:
But as you can see I have no idea how to manually get a
DocumentNode
for theValidationContext
and I have no idea how to get aFieldNode
andtypeDef
for thenodeComplexity
function.That being said I don't even know if this would be the right way to do this, maybe I'm missing something?
The text was updated successfully, but these errors were encountered: