graphql-sources 1.5.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91917cfffbb3f024443e890da6294499029638a4673e9ef96d1b061117356016
4
- data.tar.gz: 5f27027876a07800b499a9cd22832707e0b2fdb74778896d3b8b53693ce3df17
3
+ metadata.gz: fea99d5034323ff95b35a9d8e8d9ef4f549c36972c66f2958767c804a733c34a
4
+ data.tar.gz: db5ccdc4cabf4d10118e9572ebc88ccff7acf6837f333356db49a2ae5d626ddb
5
5
  SHA512:
6
- metadata.gz: 61889bbe42856b8d18e11bf3cd0dbb3f8eeea81e979f97b79f5f8334083636514637746db0d064caa2e4db45eaefbfe3af842361f0f03c436f59f3f70a40bdc0
7
- data.tar.gz: 932074f604d8490897ef8868e0f8562e04c715a3c0e89f670682f245644b25513743146c8e22d2ca35fbe969f79035485269a12c31914fbe69c6f19419beb39d
6
+ metadata.gz: 17b6e588ca2f514000c7ee9e3d1ace997b44bdb8ef43049611bf86d86711f1619bf65aa9c26305b33e00a05883a6873ed68902e7e06fcf8c223adad54787caa5
7
+ data.tar.gz: a66bd4b062d28915d1df9e904877a317ea5cc80f9cac6cbb7a3104503575220d2fce6730551c05f6421dfeb34ee62f8853824379f000d689b88d908a54f86f8f
data/README.md CHANGED
@@ -21,147 +21,138 @@ end
21
21
 
22
22
  ## Usage
23
23
 
24
- ### Loading `has_and_belongs_to_many` Associations
24
+ ### Loading `belongs_to` / `has_many` Associations
25
25
 
26
26
  ```ruby
27
- class Student
28
- has_and_belongs_to_many :courses
27
+ class Purchase < ActiveRecord::Base
28
+ belongs_to :customer
29
29
  end
30
30
  ```
31
31
 
32
32
  ```ruby
33
- class Course
34
- has_and_belongs_to_many :students
33
+ class Customer < ActiveRecord::Base
34
+ has_many :purchases
35
35
  end
36
36
  ```
37
37
 
38
38
  ```ruby
39
- class StudentType < GraphQL::Schema::Object
40
- field :courses, [CourseType], null: false
39
+ class PurchaseType < GraphQL::Schema::Object
40
+ field :customer, CustomerType, null: false
41
41
 
42
- # @return [Array<Course>]
43
- def courses
44
- # SELECT "courses_students".* FROM "courses_students" WHERE "courses_students"."student_id" = IN (...)
45
- # SELECT "courses".* FROM "courses" WHERE "courses"."id" IN (...)
42
+ # @return [Customer]
43
+ def customer
44
+ # SELECT * FROM "customers" WHERE "customers"."id" IN (...)
46
45
  dataloader
47
- .with(GraphQL::Sources::ActiveRecordAssociation, :courses)
46
+ .with(GraphQL::Sources::ActiveRecordAssociation, :customer)
48
47
  .load(object)
49
48
  end
50
49
  end
51
50
  ```
52
51
 
53
52
  ```ruby
54
- class CourseType < GraphQL::Schema::Object
55
- field :students, [StudentType], null: false
53
+ class CustomerType < GraphQL::Schema::Object
54
+ field :purchases, [PurchaseType], null: false
56
55
 
57
- # @return [Array<Student>]
58
- def students
59
- # SELECT "courses_students".\* FROM "courses_students" WHERE "courses_students"."course_id" = IN (...)
60
- # SELECT "students".\* FROM "students" WHERE "students"."id" IN (...)
56
+ def purchases
57
+ # SELECT * FROM "customers" WHERE "customers"."id" IN (...)
61
58
  dataloader
62
- .with(GraphQL::Sources::ActiveRecordAssociation, :students)
59
+ .with(GraphQL::Sources::ActiveRecordAssociation, :purchases)
63
60
  .load(object)
64
61
  end
65
62
  end
66
63
  ```
67
64
 
68
- ### Loading `belongs_to` Associations
65
+ ### Loading `belongs_to` / `has_one` Associations
69
66
 
70
67
  ```ruby
71
- class Purchase < ActiveRecord::Base
72
- belongs_to :visitor
68
+ class Profile < ActiveRecord::Base
69
+ belongs_to :user
73
70
  end
74
71
  ```
75
72
 
76
73
  ```ruby
77
- class Customer < ActiveRecord::Base
78
- has_many :purchases
74
+ class User < ActiveRecord::Base
75
+ has_one :profile
79
76
  end
80
77
  ```
81
78
 
82
79
  ```ruby
83
- class PurchaseType < GraphQL::Schema::Object
84
- field :customer, [CustomerType], null: false
80
+ class ProfileType < GraphQL::Schema::Object
81
+ field :user, [UserType], null: false
85
82
 
86
- def customer
83
+ # @return [User]
84
+ def user
85
+ # SELECT * FROM "users" WHERE "users"."id" IN (...)
87
86
  dataloader
88
- .with(GraphQL::Sources::ActiveRecordObject, ::Profile, key: :id)
89
- .load(object.customer_id)
87
+ .with(GraphQL::Sources::ActiveRecordAssociation, :user)
88
+ .load(object)
90
89
  end
91
90
  end
92
91
  ```
93
92
 
94
- ### Loading `has_one` Associations
95
-
96
- ```ruby
97
- class Profile < ActiveRecord::Base
98
- belongs_to :user
99
- end
100
- ```
101
-
102
- ```ruby
103
- class User < ActiveRecord::Base
104
- has_one :profile
105
- end
106
- ```
107
-
108
93
  ```ruby
109
94
  class UserType < GraphQL::Schema::Object
110
95
  field :profile, [ProfileType], null: false
111
96
 
97
+ # @return [Profile]
112
98
  def profile
99
+ # SELECT * FROM "profiles" WHERE "profiles"."id" IN (...)
113
100
  dataloader
114
- .with(GraphQL::Sources::ActiveRecordObject, ::Profile, key: :user_id)
115
- .load(object.id)
101
+ .with(GraphQL::Sources::ActiveRecordAssociation, :profile)
102
+ .load(object)
116
103
  end
117
104
  end
118
105
  ```
119
106
 
120
- ```sql
121
- SELECT "profiles".*
122
- FROM "profiles"
123
- WHERE "profiles"."user_id" IN (...)
124
- ORDER BY "profiles"."id"
125
- ```
126
-
127
- ### Loading `has_many` Associations
107
+ ### Loading `has_and_belongs_to_many` Associations
128
108
 
129
109
  ```ruby
130
- class User
131
- has_many :comments
110
+ class Student
111
+ has_and_belongs_to_many :courses
132
112
  end
133
113
  ```
134
114
 
135
115
  ```ruby
136
- class Comment
137
- belongs_to :user
116
+ class Course
117
+ has_and_belongs_to_many :students
138
118
  end
139
119
  ```
140
120
 
141
121
  ```ruby
142
- class UserType < GraphQL::Schema::Object
143
- field :comments, [CommentType], null: false
122
+ class StudentType < GraphQL::Schema::Object
123
+ field :courses, [CourseType], null: false
144
124
 
145
- def comments
125
+ # @return [Array<Course>]
126
+ def courses
127
+ # SELECT * FROM "courses_students" WHERE "courses_students"."student_id" = IN (...)
128
+ # SELECT * FROM "courses" WHERE "courses"."id" IN (...)
146
129
  dataloader
147
- .with(GraphQL::Sources::ActiveRecordCollection, ::Comment, key: :user_id)
148
- .load(object.id)
130
+ .with(GraphQL::Sources::ActiveRecordAssociation, :courses)
131
+ .load(object)
149
132
  end
150
133
  end
151
134
  ```
152
135
 
153
- ```sql
154
- SELECT "comments".*
155
- FROM "comments"
156
- WHERE "comments"."user_id" IN (...)
157
- ORDER BY "comments"."id"
136
+ ```ruby
137
+ class CourseType < GraphQL::Schema::Object
138
+ field :students, [StudentType], null: false
139
+
140
+ # @return [Array<Student>]
141
+ def students
142
+ # SELECT * FROM "courses_students" WHERE "courses_students"."course_id" = IN (...)
143
+ # SELECT * FROM "students" WHERE "students"."id" IN (...)
144
+ dataloader
145
+ .with(GraphQL::Sources::ActiveRecordAssociation, :students)
146
+ .load(object)
147
+ end
148
+ end
158
149
  ```
159
150
 
160
151
  ### Loading `has_one_attached` Associations
161
152
 
162
153
  ```ruby
163
154
  class User
164
- has_one_attached :avatar
155
+ has_one_attached :photo
165
156
  end
166
157
  ```
167
158
 
@@ -169,7 +160,13 @@ end
169
160
  class UserType < GraphQL::Schema::Object
170
161
  field :avatar, AttachedType, null: false
171
162
 
163
+ # @return [ActiveStorage::Attachment]
172
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 (...)
173
170
  dataloader
174
171
  .with(GraphQL::Sources::ActiveStorageHasOneAttached, :avatar)
175
172
  .load(object)
@@ -189,7 +186,13 @@ end
189
186
  class UserType < GraphQL::Schema::Object
190
187
  field :photos, [AttachedType], null: false
191
188
 
189
+ # @return [Array<ActiveStorage::Attachment>]
192
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 (...)
193
196
  dataloader
194
197
  .with(GraphQL::Sources::ActiveStorageHasManyAttached, :photos)
195
198
  .load(object)
@@ -197,6 +200,47 @@ class UserType < GraphQL::Schema::Object
197
200
  end
198
201
  ```
199
202
 
203
+ ### Loading ActiveRecord Object / ActiveRecord Collection
204
+
205
+ ```ruby
206
+ class Event < ActiveRecord::Base
207
+ belongs_to :device
208
+ end
209
+ ```
210
+
211
+ ```ruby
212
+ class Device < ActiveRecord::Base
213
+ has_many :events
214
+ end
215
+ ```
216
+
217
+ ```ruby
218
+ class EventType < GraphQL::Schema::Object
219
+ field :device, DeviceType, null: false
220
+
221
+ # @return [Device]
222
+ def device
223
+ # SELECT * FROM "devices" WHERE "devices"."id" IN (...)
224
+ dataloader
225
+ .with(GraphQL::Sources::ActiveRecordObject, ::Device, key: :id)
226
+ .load(object.device_id)
227
+ end
228
+ end
229
+ ```
230
+
231
+ ```ruby
232
+ class DeviceType < GraphQL::Schema::Object
233
+ field :events, [EventType], null: false
234
+
235
+ def events
236
+ # SELECT * FROM "events" WHERE "events"."device_id" IN (...)
237
+ dataloader
238
+ .with(GraphQL::Sources::ActiveRecordCollection, ::Event, key: :device_id)
239
+ .load(object)
240
+ end
241
+ end
242
+ ```
243
+
200
244
  ### Loading Counts
201
245
 
202
246
  ```ruby
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module Sources
5
- VERSION = '1.5.1'
5
+ VERSION = '1.5.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-sources
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre