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

Use new analysis engine when using Interpreter #1918

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions guides/queries/ast_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ end

### Using Analyzers

The new query analyzers are added to the schema the same one as before with `query_analyzer`. However, to use the new analysis engine, you must opt in by using `use GraphQL::Analysis::AST`, for example:
The new query analyzers are added to the schema the same one as before with `query_analyzer`. However, to use the new analysis engine, you must opt in by using the new runtime module, [GraphQL::Execution::Interpreter](guides/queries/interpreter.md), for example:

```ruby
class MySchema < GraphQL::Schema
use GraphQL::Analysis::AST
use GraphQL::Execution::Interpreter
query_analyzer MyQueryAnalyzer
end
```
Expand Down
3 changes: 3 additions & 0 deletions guides/queries/interpreter.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ The new runtime works with class-based schemas only. Several features are no lon

These depend on the now-removed `Rewrite` step, which wasted a lot of time making often-unneeded preparation. Most of the attributes you might need from an `irep_node` are available with `extras: [...]`. Query analyzers can be refactored to be static checks (custom validation rules) or dynamic checks, made at runtime. The built-in analyzers have been refactored to run as validators.

A new style of analyzers has been added, which rely only on the query AST. By using the interpreter, you automatically opt-in
into the new analysis runtime, which is [described here](guides/queries/ast_analysis.md).

`irep_node`-based lookahead is not supported. Stay tuned for a replacement.

- `rescue_from`
Expand Down
5 changes: 0 additions & 5 deletions lib/graphql/analysis/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ module Analysis
module AST
module_function

def use(schema_defn)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to use Interpreter instead.

schema = schema_defn.target
schema.analysis_engine = GraphQL::Analysis::AST
end

# Analyze a multiplex, and all queries within.
# Multiplex analyzers are ran for all queries, keeping state.
# Query analyzers are ran per query, without carrying state between queries.
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/execution/interpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def self.use(schema_defn)
schema_defn.query_execution_strategy(GraphQL::Execution::Interpreter)
schema_defn.mutation_execution_strategy(GraphQL::Execution::Interpreter)
schema_defn.subscription_execution_strategy(GraphQL::Execution::Interpreter)
schema = schema_defn.target
schema.analysis_engine = GraphQL::Analysis::AST
end

def self.begin_multiplex(multiplex)
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/analysis/ast_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def foobar

Class.new(GraphQL::Schema) do
query query_type
use GraphQL::Analysis::AST
use GraphQL::Execution::Interpreter
query_analyzer AstErrorAnalyzer
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
GRAPHQL
}

focus
Copy link
Contributor Author

Choose a reason for hiding this comment

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

😨

it "finds usages" do
assert_equal([], errors)
end
Expand Down