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
Copy file name to clipboardExpand all lines: README.md
+33-1Lines changed: 33 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -312,7 +312,39 @@ class MyProjectSchema < GraphQL::Schema
312
312
end
313
313
```
314
314
315
-
That's it.
315
+
---
316
+
317
+
If you need to use BatchLoader with ActiveRecord in multiple places, you can use this `preload:` helper shared by [Aha!](https://www.aha.io/engineering/articles/automatically-avoiding-graphql-n-1s):
318
+
319
+
```rb
320
+
field :user, UserType, null:false, preload::user
321
+
# ^^^^^^^^^^^^^^
322
+
# Simply add this instead of defining custom `user` method with BatchLoader
323
+
```
324
+
325
+
And add this custom field resolver that uses ActiveRecord's preload functionality with BatchLoader:
0 commit comments