@@ -148,6 +148,32 @@ class CourseType < GraphQL::Schema::Object
148
148
end
149
149
```
150
150
151
+ ### Loading ` has_one_attached ` Associations
152
+
153
+ ``` ruby
154
+ class User
155
+ has_one_attached :photo
156
+ end
157
+ ```
158
+
159
+ ``` ruby
160
+ class UserType < GraphQL ::Schema ::Object
161
+ field :avatar , AttachedType , null: false
162
+
163
+ # @ return [ ActiveStorage::Attachment]
164
+ def avatar
165
+ # SELECT "active_storage_attachments".*
166
+ # FROM "active_storage_attachments"
167
+ # WHERE "active_storage_attachments"."name" = 'avatar'
168
+ # AND "active_storage_attachments"."record_type" = 'User'
169
+ # AND "active_storage_attachments"."record_id" IN (...)
170
+ dataloader
171
+ .with(GraphQL ::Sources ::ActiveStorageHasOneAttached , :avatar )
172
+ .load (object)
173
+ end
174
+ end
175
+ ```
176
+
151
177
### Loading ` has_many_attached ` Associations
152
178
153
179
``` ruby
160
186
class UserType < GraphQL ::Schema ::Object
161
187
field :photos , [AttachedType ], null: false
162
188
189
+ # @ return [ Array<ActiveStorage::Attachment>]
163
190
def photos
191
+ # SELECT "active_storage_attachments".*
192
+ # FROM "active_storage_attachments"
193
+ # WHERE "active_storage_attachments"."name" = 'photos'
194
+ # AND "active_storage_attachments"."record_type" = 'User'
195
+ # AND "active_storage_attachments"."record_id" IN (...)
164
196
dataloader
165
197
.with(GraphQL ::Sources ::ActiveStorageHasManyAttached , :photos )
166
198
.load (object)
0 commit comments