You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`Execution::Next` supports field configuration shorthands for common dataloader usage. Under the hood, these make sure data fetching is batched and cached.
141
+
142
+
#### Sources
143
+
144
+
Use a custom dataloader source from your application:
145
+
146
+
```ruby
147
+
classTypes::CommentType
148
+
# Equivalent to `dataload(Sources::CommentRating, object)`
149
+
field :rating, Integer, dataload:Sources::CommentRating
150
+
151
+
# `using:`: A method to call to get a value to pass to dataloader
152
+
# `by: [...]`: An array of arguments to pass on to dataloader
153
+
#
154
+
# Equivalent to `dataload(Sources::ReadingDuration, :comment, object.body)
155
+
field :reading_duration, Integer, dataload: { with:Sources::ReadingDuration, using::body, by: [:comment] }
156
+
```
157
+
158
+
#### Rails Associations
159
+
160
+
Load ActiveRecord associations using {{ "GraphQL::Dataloader::ActiveRecordAssociationSource" | api_doc }}:
161
+
162
+
```ruby
163
+
classTypes::CommentType < Types::BaseObject
164
+
# Equivalent to `dataload_association(:post)`
165
+
field :post, Types::Post, dataload: { association:true }
166
+
# Equivalent to `dataload_association(:user)
167
+
field :author, Types::Post, dataload: { association::user }
168
+
end
169
+
```
170
+
171
+
#### Rails Records
172
+
173
+
Load ActiveRecord associations using {{ "GraphQL::Dataloader::ActiveRecordSource" | api_doc }}.
174
+
175
+
```ruby
176
+
classTypes::SearchResult < Types::BaseObject
177
+
# Equivalent to `dataload_record(Post, object.post_id)`
178
+
field :post, Types::Post, dataload: { model:Post, using::post_id }
179
+
# Equivalent to `dataload_record(User, object.created_by_handle, find_by: :handle)`
180
+
field :author, Types::User, dataload: { model:User, using::created_by_handle, find_by::handle }
# Look up an associated record using a Rails association (via {Dataloader::ActiveRecordAssociationSource})
60
70
# @param association_name [Symbol] A `belongs_to` or `has_one` association. (If a `has_many` association is named here, it will be selected without pagination.)
61
71
# @param record [ActiveRecord::Base] The object that the association belongs to.
0 commit comments