Skip to content

Allow instances of subclasses of wrapper class to be pattern matched via #deconstruct_keys#5660

Merged
rmosolgo merged 1 commit into
rmosolgo:masterfrom
itojum:add-wrapper-pattern-matching
Jul 7, 2026
Merged

Allow instances of subclasses of wrapper class to be pattern matched via #deconstruct_keys#5660
rmosolgo merged 1 commit into
rmosolgo:masterfrom
itojum:add-wrapper-pattern-matching

Conversation

@itojum

@itojum itojum commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Added #deconstruct_keys to the GraphQL::Schema::Wrapper class. This allows pattern matching against List and NonNull, which are subclasses of the Wrapper class.

This allows using pattern matching for concise access to internal elements when dealing with nested structures.

Example:

obj = GraphQL::Schema::List.new(GraphQL::Schema::NonNull.new("Matched!"))
case obj
in GraphQL::Schema::List(of_type: GraphQL::Schema::NonNull(of_type: message))
  p message # => "Matched!"
else
  p "No match"
end

I also referred to the PR that adds #deconstruct_keys to the InputObject.
#5170

@rmosolgo rmosolgo added this to the 2.6.6 milestone Jul 7, 2026
@rmosolgo

rmosolgo commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Looks good, thanks for this improvement 👍

@rmosolgo rmosolgo merged commit e681f8d into rmosolgo:master Jul 7, 2026
11 of 13 checks passed
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.

2 participants