Skip to content
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

Merged
merged 31 commits into from
Oct 10, 2018
Merged

AST analyzers #1841

merged 31 commits into from
Oct 10, 2018

Conversation

xuorig
Copy link
Contributor

@xuorig xuorig commented Sep 7, 2018

No description provided.

@rmosolgo
Copy link
Owner

rmosolgo commented Sep 7, 2018

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.

Copy link
Contributor

@RobertWSaunders RobertWSaunders left a 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!

@rmosolgo rmosolgo added this to the 1.9.0 milestone Sep 13, 2018
@xuorig xuorig changed the title Big WIP: spike at AST analyzers AST analyzers Oct 1, 2018
Copy link
Owner

@rmosolgo rmosolgo left a 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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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.

Copy link
Contributor Author

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.

@rmosolgo rmosolgo mentioned this pull request Oct 5, 2018
19 tasks
@xuorig
Copy link
Contributor Author

xuorig commented Oct 6, 2018

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.

@xuorig
Copy link
Contributor Author

xuorig commented Oct 6, 2018

Tests mostly pass except a weird case with a prepare proc returning an execution error during analysis, not sure how this was handled before, will debug on monday.

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 🤔

Copy link
Owner

@rmosolgo rmosolgo left a 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.

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`
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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.

@@ -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
Copy link
Owner

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?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes and yes!

@xuorig
Copy link
Contributor Author

xuorig commented Oct 10, 2018

🍏 ! Ready for an other round or reviews @rmosolgo 🙏

Copy link
Owner

@rmosolgo rmosolgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 🎉 !

@rmosolgo rmosolgo merged commit 4ca8545 into rmosolgo:1.9-dev Oct 10, 2018
@xuorig xuorig deleted the ast-analyzers branch October 10, 2018 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants