-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
AST analyzers #1841
AST analyzers #1841
Conversation
Some quick feedback here: it's important that we keep supporting existing Analysis for people who don't opt into the new interpreter, so new-style analyzers should be implemented as a brand new code path, leaving the existing code in place. |
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 looks awesome! Noticed one small thing while reading your docs!
89957d7
to
190637a
Compare
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.
Taking a high-level look, this looks really solid! Lots of contextual helpers for an AST visit.
@@ -1,7 +1,7 @@ | |||
# frozen_string_literal: true | |||
require "spec_helper" | |||
|
|||
describe GraphQL::Analysis::QueryDepth do | |||
describe GraphQL::Analysis::AST::QueryDepth do |
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.
Should this have AST::
?
super | ||
@complexities_on_type = [TypeComplexity.new] | ||
@skip_stack = [false] | ||
@in_fragment_def = false |
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.
It looks like some of these IVars were moved to the parent class, is that right?
|
||
def on_leave_fragment_spread(node, _, visitor) | ||
visitor.leave_fragment_spread_inline(node) | ||
end |
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.
It'll be interesting to see if we need this more, maybe a kind of base class that defaults to this handling of fragments will come in handy.
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.
💯 Totally. I was unsure if we needed this now. The base class idea sounds good. If a more "raw" approach is needed they could use this method to do it, but the more common default definitly sounds more like visiting the fragment spreads inline.
Worked on exposing this new API. To keep the existing analysis working, it is possible to switch the analysis engine at the schema level. The new AST analysis engine is opt in, like this: class MySchema < GraphQL::Schema
use GraphQL::Analysis::AST
query_analyzer MyASTAnalyzer
end The same hook is used to add AST analyzers or old analyzers, but the selected engine treats them how it wants. It might be good to eventually add a way to select the engine at the validation pipeline / query level. Might be useful to A/B test while migrating for example. |
Tests mostly pass except a weird case with a Edit: ah ok, the authorization analyzer was only added when you used class based before, I need to modify the validation pipeline to check for that 🤔 |
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.
Looks good! I just had a few questions about the test setup and I think we're set to merge.
If we stick to the plan of removing the authorization analyzer, I'll update the docs later.
lib/graphql/language/visitor.rb
Outdated
alias :on_union_type_extension :on_abstract_node | ||
alias :on_variable_definition :on_abstract_node | ||
alias :on_variable_identifier :on_abstract_node | ||
# Don't use make_visit_method becuase it breaks `super` |
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 should probably be "Don't use alias because it breaks super
, right?
@@ -159,6 +160,7 @@ def initialize | |||
@lazy_methods.set(GraphQL::Execution::Lazy, :value) | |||
@cursor_encoder = Base64Encoder | |||
# Default to the built-in execution strategy: | |||
@analysis_engine = GraphQL::Analysis |
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.
👍 nice approach to generalizing this
.travis.yml
Outdated
@@ -43,6 +43,7 @@ matrix: | |||
- env: | |||
- DISPLAY=':99.0' | |||
- TESTING_INTERPRETER=yes | |||
- TESTING_AST_ANALYSIS=yes |
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 test case only runs the ActionCable subscription tests from spec/dummy
, did you mean to set this flag for those tests? I don't see the flag used by those tests.
spec/graphql/authorization_spec.rb
Outdated
@@ -372,6 +372,9 @@ class Schema < GraphQL::Schema | |||
if TESTING_INTERPRETER | |||
use GraphQL::Execution::Interpreter | |||
end | |||
if TESTING_AST_ANALYSIS | |||
use GraphQL::Analysis::AST | |||
end |
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.
Should this be removed, since we're bailing on that analyzer? (If it should be removed, then I think we can remove TESTING_AST_ANALYSIS altogether, right?)
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.
yes and yes!
🍏 ! Ready for an other round or reviews @rmosolgo 🙏 |
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.
👏 🎉 !
No description provided.