Postponed
Project:
Drupal core
Version:
main
Component:
jsonapi.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
16 Jul 2018 at 23:53 UTC
Updated:
9 Sep 2020 at 13:25 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
gabesullicegabesullice created an issue.
[PP-1]because #2985426: Spec compliance: `related` routes should return 200, not 403, if field access is allowed but the related resources are forbidden has not yet landed.Comment #2
wim leers#2985426: Spec compliance: `related` routes should return 200, not 403, if field access is allowed but the related resources are forbidden landed!
Comment #3
wim leers#2993654: Provide JSON Pointer as a link on a resource to ease matching with included items perhaps makes this less necessary.I also wonder what the consequences are of paginated includes: how would one even specify which page of includes for which field to load? It'd still result in multiple requests then, mostly defeating the purpose of includes?I think it may make sense to remove the "paginated" portion of the issue's intent/scope.I misinterpreted. See below.
Comment #4
wim leersComment #5
gabesulliceThis issue is not about includes, but the resource objects at a path like
/jsonapi/node/article/{uuid}/tags. So, if the article has 200 tags it would be nice to be able to filter, sort and page them.Comment #6
wim leersHah, whoops! I was triaging the issue queue, and clearly misinterpreted this one. Struck through all of #3.
Comment #7
wim leersHow would this work?
I think it'd mean duplicating much of
\Drupal\jsonapi\Controller\EntityResource::getCollection()ingetRelated()and just automatically adding conditions to the query that ensure it's limited to those resources related to the base resource.Comment #8
gabesullice#7: Yep. See #2985426-7: Spec compliance: `related` routes should return 200, not 403, if field access is allowed but the related resources are forbidden where I did exactly that. It was reverted in #35 because it was out of scope. This issue is the followup for it.
Comment #9
wim leersAlright, cool, then whenever we do this we don't need to start from scratch. Marking NW to reflect that state.
Comment #10
gabesulliceFTFY
Comment #11
wim leers😅
Comment #12
wim leersThere are two steps to be taken here:
\Drupal\jsonapi\Controller\EntityResource::getRelated()just calls$entity->get($related_field_name)->referencedEntities()today, and doesn't do an Entity Field Query. Which means we actually cannot "just" do filtering, sorting and pagination. We have to convert this to an entity query first.filter,pageandsortparameters.That's where we run into a similar problem to what we encountered in #3022531-2: (Re)move _json_api_params from JsonApiParamEnhancer and do not use denormalization for them, and we solved it there by moving the creation of the
Filtervalue object out of a route enhancer (\Drupal\jsonapi\Routing\JsonApiParamEnhancer) and into the controller (\Drupal\jsonapi\Controller\EntityResource) where it is about to be used.JsonApiParamEnhancerassumes it operates on the resource type of the route, and for therelatedroute that is the host resource type, not the related one. So thesortandpagehandling in\Drupal\jsonapi\Routing\JsonApiParamEnhancer::enhance()cannot possibly give us the right results.For
filter, we'd need to call the existing helper method. But … when dealing withrelateddata, there can be multiple resource types. How do we sort and paginate across resource types?Given the above, I'm not so sure that this is truly worth doing. This is hugely complex. And despite this issue turning six months old today, zero people besides the two of us are following this. I think we should consider closing this.
Comment #13
wim leersComment #14
gabesulliceThe underlying problem here is really that we can't yet support collections of mixed-bundles. Once that is possible, this will be trivial.
I think it's naive to assume that this feature is not worth doing because no-one is following this issue. If we supported this, we'd be a lot closer to being able to automatically support reverse relationship routes. This would be hugely valuable.
The two blockers are:
#3022531: (Re)move _json_api_params from JsonApiParamEnhancer and do not use denormalization for them
#3031173: FieldResolver::resolveInternalEntityQueryPath should accept an array of resource types, not a single resource type
Comment #15
wim leersIt's late over here and perhaps that's why I'm not making the connection. Can you explain this? That alone would make this IMHO.
Comment #16
gabesulliceImagine you run an American sports magazine website. You have a vocabulary of sports (Basketball, Football, Soccer, etc). And 100,000 articles that are tagged with one of these sports.
Right now, you can visit
/jsonapi/node/article?filter[field_sport]={uuid of the football term}This route obviously supports pagination and filtering. That's good because you're potentially dealing with tens of thousands of results.
A reverse relationship route like this:
/jsonapi/taxonomy_term/sports/{uuid of the football term}/node/field_sportWould be catastrophic unless we supported filtering and pagination. In our example, it would almost always time out (since there's no mechanism to page the results).
Currently, related routes can suffer from this too, it's just that most applications don't have entity reference fields with hundreds or thousands of referenced entities.
You might think, well, can't we just make reverse references behave just like collections? Those work, right? Unfortunately not, because related routes can have >1 resource type in them and the field resolver can't handle that. They're effectively mixed-bundle collections (without an entity query).
So my logic is: if we can "support sortable, paginated and filterable related resources", that means we can support reverse relationships safely without timing out or crashing servers.
Comment #17
vincenzo gambino commentedHi,
I am having this issue right now. I would like to paginate or limit relationships.
I would like to implement the pagination/limit in the relationship endpoint? /jsonapi/node/uuid/relationships/field_name?page[limit]=1
Is this what you are planning to do here?
Comment #18
gabesullice@Vincenzo Gambino, not really. This issue would address:
/jsonapi/node/uuid/field_name?page[limit]=1not
/jsonapi/node/uuid/relationships/field_name?page[limit]=1So, the route that list the related entities, not the relationships to those entities.
Perhaps you can open another feature request for your use case? Knowing the underlying implementation, I think it would be difficult to handle both routes in this issue.
Comment #19
gabesullice#3022531: (Re)move _json_api_params from JsonApiParamEnhancer and do not use denormalization for them landed.
Moving this to the Drupal core JSON:API component.