@@ -14,14 +14,15 @@ def apply
1414 end
1515
1616 class FindOperation < Operation
17- attr_reader :filters , :include_directives , :sort_criteria , :paginator
17+ attr_reader :filters , :include_directives , :sort_criteria , :paginator , :fields
1818
1919 def initialize ( resource_klass , options = { } )
2020 super ( resource_klass , options )
2121 @filters = options [ :filters ]
2222 @include_directives = options [ :include_directives ]
2323 @sort_criteria = options . fetch ( :sort_criteria , [ ] )
2424 @paginator = options [ :paginator ]
25+ @fields = options [ :fields ]
2526 @transactional = false
2627 end
2728
@@ -52,7 +53,8 @@ def apply
5253 context : @context ,
5354 include_directives : @include_directives ,
5455 sort_criteria : @sort_criteria ,
55- paginator : @paginator )
56+ paginator : @paginator ,
57+ fields : @fields )
5658
5759 options = { }
5860 if JSONAPI . configuration . top_level_links_include_pagination
@@ -77,12 +79,13 @@ def apply
7779 end
7880
7981 class ShowOperation < Operation
80- attr_reader :id , :include_directives
82+ attr_reader :id , :include_directives , :fields
8183
8284 def initialize ( resource_klass , options = { } )
8385 super ( resource_klass , options )
8486 @id = options . fetch ( :id )
8587 @include_directives = options [ :include_directives ]
88+ @fields = options [ :fields ]
8689 @transactional = false
8790 end
8891
@@ -91,7 +94,8 @@ def apply
9194
9295 resource_record = @resource_klass . find_by_key ( key ,
9396 context : @context ,
94- include_directives : @include_directives )
97+ include_directives : @include_directives ,
98+ fields : @fields )
9599
96100 return JSONAPI ::ResourceOperationResult . new ( :ok , resource_record )
97101
@@ -123,18 +127,19 @@ def apply
123127 end
124128
125129 class ShowRelatedResourceOperation < Operation
126- attr_reader :source_klass , :source_id , :relationship_type
130+ attr_reader :source_klass , :source_id , :relationship_type , :fields
127131
128132 def initialize ( resource_klass , options = { } )
129133 super ( resource_klass , options )
130134 @source_klass = options . fetch ( :source_klass )
131135 @source_id = options . fetch ( :source_id )
132136 @relationship_type = options . fetch ( :relationship_type )
137+ @fields = options [ :fields ]
133138 @transactional = false
134139 end
135140
136141 def apply
137- source_resource = @source_klass . find_by_key ( @source_id , context : @context )
142+ source_resource = @source_klass . find_by_key ( @source_id , context : @context , fields : @fields )
138143
139144 related_resource = source_resource . public_send ( @relationship_type )
140145
@@ -146,7 +151,7 @@ def apply
146151 end
147152
148153 class ShowRelatedResourcesOperation < Operation
149- attr_reader :source_klass , :source_id , :relationship_type , :filters , :sort_criteria , :paginator
154+ attr_reader :source_klass , :source_id , :relationship_type , :filters , :sort_criteria , :paginator , :fields
150155
151156 def initialize ( resource_klass , options = { } )
152157 super ( resource_klass , options )
@@ -156,6 +161,7 @@ def initialize(resource_klass, options = {})
156161 @filters = options [ :filters ]
157162 @sort_criteria = options [ :sort_criteria ]
158163 @paginator = options [ :paginator ]
164+ @fields = options [ :fields ]
159165 @transactional = false
160166 end
161167
@@ -170,7 +176,7 @@ def page_count
170176 end
171177
172178 def source_resource
173- @_source_resource ||= @source_klass . find_by_key ( @source_id , context : @context )
179+ @_source_resource ||= @source_klass . find_by_key ( @source_id , context : @context , fields : @fields )
174180 end
175181
176182 def records
@@ -200,7 +206,8 @@ def apply
200206 related_resource = source_resource . public_send ( @relationship_type ,
201207 filters : @filters ,
202208 sort_criteria : @sort_criteria ,
203- paginator : @paginator )
209+ paginator : @paginator ,
210+ fields : @fields )
204211
205212 return JSONAPI ::RelatedResourcesOperationResult . new ( :ok , source_resource , @relationship_type , related_resource , options )
206213
@@ -210,11 +217,12 @@ def apply
210217 end
211218
212219 class CreateResourceOperation < Operation
213- attr_reader :data
220+ attr_reader :data , :fields
214221
215222 def initialize ( resource_klass , options = { } )
216223 super ( resource_klass , options )
217224 @data = options . fetch ( :data )
225+ @fields = options [ :fields ]
218226 end
219227
220228 def apply
@@ -247,12 +255,13 @@ def apply
247255 end
248256
249257 class ReplaceFieldsOperation < Operation
250- attr_reader :data , :resource_id
258+ attr_reader :data , :resource_id , :fields
251259
252260 def initialize ( resource_klass , options = { } )
253261 super ( resource_klass , options )
254262 @resource_id = options . fetch ( :resource_id )
255263 @data = options . fetch ( :data )
264+ @fields = options [ :fields ]
256265 end
257266
258267 def apply
0 commit comments