Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

amomchilov
Copy link
Owner

No description provided.

@amomchilov amomchilov force-pushed the Alex/skip-list-items-wip branch 2 times, most recently from 2e3636e to 3ff5afa Compare May 26, 2023 17:10
Copy link
Owner Author

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

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

@amomchilov amomchilov May 26, 2023

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)

transforms.reverse_each { |t| type = type.public_send(t) }

Comment on lines +21 to +25
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
Copy link
Owner Author

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

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

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

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

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

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

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?

Comment on lines 35 to 38
def to_s = inspect

Copy link
Owner Author

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

@amomchilov amomchilov force-pushed the Alex/skip-list-items-wip branch 4 times, most recently from e904ef5 to b2d9e9d Compare May 31, 2023 01:32
@amomchilov amomchilov force-pushed the Alex/skip-list-items-wip branch from b2d9e9d to 6315fcb Compare May 31, 2023 20:34
@amomchilov amomchilov closed this May 31, 2023
@amomchilov amomchilov deleted the Alex/skip-list-items-wip branch May 31, 2023 22:15
@amomchilov
Copy link
Owner Author

Opened a PR to our own fork of the gem: Shopify#6

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.

1 participant