-
-
Notifications
You must be signed in to change notification settings - Fork 2
Test suite for the type complexity analysis algorithm #23
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
Conversation
…rk of the test suite to test its functionality
… as being type complexity only
…o em/complexityTests
… supposed ot work
|
Re: your second question about taking into account As for unbounded lists. I'm not sure and I don't see a way to precompute this without having access to the database. We could have this to default to some value, make it configurable or cache the complexity each time an unbounded collection is resolved. The first call would be 'free' but after that there would be a somewhat accurate estimate assuming the list is called frequently enough I'll poke around some of the existing packages and see if they handle this case. |
| * | ||
| * Some user configuration will be needed unless someone has bright ideas. | ||
| */ | ||
| // ? type weigts are variable, not sure how to calculate this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the question on line 259 how to calculate this in the actual implementation or in the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is was with regards to implementing the algorithm. It was meant describe my thinking at that point and to imply that this test was weakly written. I can't say with any confidence that we should expect a complexity of 7 from this query. I'll skip it and make that clear until we figure how to handle these scenarios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that we discussed the implementation using DFS/backtracking to compute complexity of nested queries.
| // What would that look like here? I think we should throw ar error from this function. | ||
| test('Throws an error if for a bad query', () => { | ||
| query = `Query { hello { hi } }`; // type doesn't exist | ||
| expect(getQueryTypeComplxity(query, typeWeights)).toThrow('Error'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor but missing a 'e' in getQueryTypeComplxity and you can just use .toThrow() which checks if any error is thrown.
I agree on this function throwing an error. A question for the middleware then is do we want to pass the error down the middleware chain or send back a 400 status indicating a malformed request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking we pass it onto to GraphQL to handle, so that thir error handling can respond with their error messages. We can discuss.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use the parse() method and can respond to the client in the same way that GraphQL does then we can send the error back to the client. Otherwise calling next() will just let GraphQL handle this.
- Let's create an issue to dive further into error handling
…raphQL-Gate into em/complexityTests
…de the function definition for the lists.
Summary
Changes are not 100% ready but I am requesting feedback and input on 1 particular problem I am having.
When working with lists in graphQL, the type complexity of the query is dependent on the number of objects returned in the list. For example, on
line 263intypeComplexityAnalysis.test.ts:the field
friendsis a list that returns an unknown number of objects in the response. How would we account for this when writing the complexity algorithm? Does this need to be accounted for thebuildTypeWeightsfunction?Similarly on
line 271intypeComplexityAnalysis.test.ts,the number of objects in the response is 3, but it could 4, or 5. It's variable based on the client requests. Should the
typeComplextyAnalysisalgorithm take in the query variables as an argument in order to estimate maximum size that the response could be?Type of Change
Issues
closes #8
Evidence