-
Notifications
You must be signed in to change notification settings - Fork 0
WIP: Skip over list items that raise errors #1
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
2e3636e
to
3ff5afa
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.
Notes to self
# @return [nil, true] | ||
attr_accessor :graphql_skip_list_items_that_raise | ||
|
||
def has_graphql_graph_parent_that_skips_list_items_that_raise |
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.
TODO: comically long name lol
@@ -17,15 +17,24 @@ def to_non_null_type | |||
end | |||
|
|||
# @return [Schema::List] Make a list-type representation of this type | |||
def to_list_type | |||
@to_list_type ||= GraphQL::Schema::List.new(self) | |||
def to_list_type(skip_nodes_on_raise: 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.
I used a default value here, because there's a fair number of callsites the way Addition#update_type_owner
calls this reflectively can't pass an extra parameter (without changing it a fair bit)
graphql-ruby/lib/graphql/schema/addition.rb
Line 135 in f88ec1f
transforms.reverse_each { |t| type = type.public_send(t) } |
if skip_nodes_on_raise | ||
@to_skipping_list_type ||= GraphQL::Schema::List.new(self, skip_nodes_on_raise: true) | ||
else | ||
@to_list_type ||= GraphQL::Schema::List.new(self) | ||
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.
Is this weird?
rescue GraphQL::ExecutionError => ex_err | ||
ex_err | ||
if selection_result.has_graphql_graph_parent_that_skips_list_items_that_raise | ||
nil |
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.
The existing nil-propagation mechanism works to ... propagate nil. I'm piggy-backing off it here. Should I propagate the raised error instead of nil?
If so, how do I identify that, down the line?
query.handle_or_reraise(err) | ||
rescue GraphQL::ExecutionError => ex_err | ||
ex_err | ||
if selection_result.has_graphql_graph_parent_that_skips_list_items_that_raise |
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.
API design question: before skipping an item, should we called the users rescue_from
callback? (or perhaps make a new callback specific to item skipping?)
This if
statement skips it for now, and silently skips the item. This isn't ideal, because the service owner wouldn't know items are being skipped. (e.g. if rescue_from
reports to a bug tracker, it won't be called).
@@ -545,10 +560,32 @@ def dead_result?(selection_result) | |||
|
|||
def set_result(selection_result, result_name, value) | |||
if !dead_result?(selection_result) | |||
if value.nil? && | |||
if value == GraphQL::Execution::SKIP |
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.
TODO: this is kinda bodged in. Rework.
if selection_result.has_graphql_graph_parent_that_skips_list_items_that_raise | ||
# This writes the `nil` in, we need to patch it to skip instead. | ||
print("skip!") | ||
set_result(selection_result, result_name, GraphQL::Execution::SKIP) |
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.
Fixme: this is abusing GraphQL::Execution::SKIP
as a flag parameter/sentinel
@@ -466,7 +466,7 @@ def build_resolve_type(lookup_hash, directives, missing_type_handler) | |||
when GraphQL::Language::Nodes::NonNullType | |||
resolve_type_proc.call(ast_node.of_type).to_non_null_type | |||
when GraphQL::Language::Nodes::ListType | |||
resolve_type_proc.call(ast_node.of_type).to_list_type | |||
resolve_type_proc.call(ast_node.of_type).to_list_type(skip_nodes_on_raise: 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.
FIXME: how should this work?
@@ -271,6 +271,7 @@ def initialize(type: nil, name: nil, owner: nil, null: nil, description: :not_gi | |||
else | |||
true | |||
end | |||
@skip_nodes_on_raise = skip_nodes_on_raise |
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 just a hack to make this value avaiable in #type
.
Should this be encoded in the @return_type_expr
somehow?
lib/graphql/schema/non_null.rb
Outdated
def to_s = inspect | ||
|
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.
For the debugger only; remove
e904ef5
to
b2d9e9d
Compare
b2d9e9d
to
6315fcb
Compare
Opened a PR to our own fork of the gem: Shopify#6 |
No description provided.