-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ group :jekyll_plugins do | |
gem 'jekyll-algolia', '~> 1.0' | ||
gem 'jekyll-redirect-from' | ||
end | ||
|
||
gem 'awesome_print' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,7 +219,7 @@ def method_conflict_warning? | |
# @param method_conflict_warning [Boolean] If false, skip the warning if this field's method conflicts with a built-in method | ||
# @param validates [Array<Hash>] Configurations for validating this field | ||
# @fallback_value [Object] A fallback value if the method is not defined | ||
def initialize(type: nil, name: nil, owner: nil, null: nil, description: :not_given, deprecation_reason: nil, method: nil, hash_key: nil, dig: nil, resolver_method: nil, connection: nil, max_page_size: :not_given, default_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: nil, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, fallback_value: :not_given, &definition_block) | ||
def initialize(type: nil, name: nil, owner: nil, null: nil, description: :not_given, deprecation_reason: nil, method: nil, hash_key: nil, dig: nil, resolver_method: nil, connection: nil, max_page_size: :not_given, default_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: nil, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, fallback_value: :not_given, skip_nodes_on_raise: false, &definition_block) | ||
if name.nil? | ||
raise ArgumentError, "missing first `name` argument or keyword `name:`" | ||
end | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This is just a hack to make this value avaiable in Should this be encoded in the |
||
@connection = connection | ||
@has_max_page_size = max_page_size != :not_given | ||
@max_page_size = max_page_size == :not_given ? nil : max_page_size | ||
|
@@ -349,6 +350,11 @@ def initialize(type: nil, name: nil, owner: nil, null: nil, description: :not_gi | |
|
||
self.extensions.each(&:after_define_apply) | ||
@call_after_define = true | ||
|
||
# TODO: should this check be centralized in `GraphQL::Schema::Member::BuildType#parse_type` instead? | ||
if skip_nodes_on_raise && !self.type.list? | ||
raise ArgumentError, "The `skip_nodes_on_raise` option is only applicable to lists." | ||
end | ||
end | ||
|
||
# If true, subscription updates with this field can be shared between viewers | ||
|
@@ -572,9 +578,10 @@ def type | |
raise MissingReturnTypeError, "Can't determine the return type for #{self.path} (it has `resolver: #{@resolver_class}`, perhaps that class is missing a `type ...` declaration, or perhaps its type causes a cyclical loading issue)" | ||
end | ||
nullable = @return_type_null.nil? ? @resolver_class.null : @return_type_null | ||
Member::BuildType.parse_type(return_type, null: nullable) | ||
skip_nodes_on_raise = @skip_nodes_on_raise.nil? ? @resolver_class.skip_nodes_on_raise : @skip_nodes_on_raise | ||
Member::BuildType.parse_type(return_type, null: nullable, skip_nodes_on_raise: skip_nodes_on_raise) | ||
else | ||
@type ||= Member::BuildType.parse_type(@return_type_expr, null: @return_type_null) | ||
@type ||= Member::BuildType.parse_type(@return_type_expr, null: @return_type_null, skip_nodes_on_raise: @skip_nodes_on_raise) | ||
end | ||
rescue GraphQL::Schema::InvalidDocumentError, MissingReturnTypeError => err | ||
# Let this propagate up | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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 commentThe 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 graphql-ruby/lib/graphql/schema/addition.rb Line 135 in f88ec1f
|
||||
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 | ||||
Comment on lines
+21
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this weird? |
||||
end | ||||
|
||||
# @return [Boolean] true if this is a non-nullable type. A nullable list of non-nullables is considered nullable. | ||||
def non_null? | ||||
false | ||||
end | ||||
|
||||
# @return [Boolean] true if this field's nodes should be skipped, if resolving them led to an error being raised. | ||||
def skip_nodes_on_raise? | ||||
false | ||||
end | ||||
|
||||
# @return [Boolean] true if this is a list type. A non-nullable list is considered a list. | ||||
def list? | ||||
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?