\Drupal\jsonapi\Context\FieldResolver::resolveInternalEntityQueryPath accepts a resource type object, but later wraps it as an array. The resolveInternalEntityQueryPath should accept an array of resource types by default. This helps unblock contributed projects that interact with JSON:API to extend its functionality such as JSON:API Cross Bundles.
The method was refactored in #3070204: Refactor the JSON:API FieldResolver to use a resource type instead of an entity type ID and bundle ID pair to accept a resource type value. Prior to that issue, the method received an entity type ID and bundle which is converted to a resource type and wrapped in an array. This issue is a follow up to rectify the fact we cannot pass an array of resource types and receive the internal entity query path.
Support for passing in multiple resource types unblocks performing entity queries across bundles with JSON:API.
Original summary
This is a major impediment for support for mixed-bundle collections (https://www.drupal.org/project/jsonapi_cross_bundles) and sortable/filterable/paginated related collection routes. Support for the latter would enable us to have automatic support for "reverse" related routes.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3031173-11.patch | 4.46 KB | mglaman |
| #10 | 3031173-10.patch | 2.59 KB | mglaman |
Comments
Comment #2
gabesulliceComment #3
gabesullicePostponing this on a prerequisite refactoring: #3070204: Refactor the JSON:API FieldResolver to use a resource type instead of an entity type ID and bundle ID pair
Comment #4
gabesulliceComment #5
gabesulliceComment #6
wim leers#3070204: Refactor the JSON:API FieldResolver to use a resource type instead of an entity type ID and bundle ID pair landed! 🥳
Comment #7
jibranThis is a contrib blocker, right?
Comment #8
wim leersIt is.
Comment #10
mglamanTrying to remember the initial discussions for this. Would it be to allow passing in resource types for each Node bundle and ensuring the internal field path exists?
Here is a patch to at least rekindle the discussion.
Comment #11
mglamanHere's an updated patch to include a test.
Comment #12
mglamanUpdated the issue summary.
Comment #13
mglamanDiscussed with @gabesullice in Slack. We can use this not just for the jsonapi_cross_bundle module but also
relatedroutes already provided.For example,
/jsonapi/user/user/{uuid}/publicationscould be a mixed-bundle relationship of nodes. I'll work on a quick test to check if running includes on related routes works with or without this patch.Comment #14
jibranIS looks good. Thanks for the update.
Let's simplify this this and DRY at the same time.
array map/walk $resource_types and throw exception. Do we need tests the exception?
Comment #15
mglamanIf a map/walk necessary? We're not manipulating values, so a foreach is fine. JSON:API does use an assert for checking all items in an array are of a type, so maybe we can use that. I don't think JSON:API tests any of its exceptions like that.
Comment #19
bbralaSeems there is some open feedback so moving it back to needs work. Seems like a usefull change that opens up a few helpfull possibilities.