Skip to content

Commit a03f81d

Browse files
authored
Fix custom field code example errors
There are a couple of errors in the code example that resulted in it not working. (field_options needs to be expanded apparently, and the blocks are evaluated in the instance context, not passing in a `self`). This resolves the issue.
1 parent c44aee1 commit a03f81d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

guides/fields/resolvers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ end
4242

4343
```ruby
4444
# Generate a field which returns a filtered, sorted list of items
45-
def self.items_field(name, override_options)
45+
def self.items_field(name, override_options, &block)
4646
# Prepare options
4747
default_field_options = { type: [Types::Item], null: false }
4848
field_options = default_field_options.merge(override_options)
4949
# Create the field
50-
field(name, field_options) do
50+
field(name, **field_options) do
5151
argument :order_by, Types::ItemOrder, required: false
5252
argument :category, Types::ItemCategory, required: false
5353
# Allow an override block to add more arguments
54-
yield self if block_given?
54+
instance_eval(&block) if block_given?
5555
end
5656
end
5757

0 commit comments

Comments
 (0)