In #3010432: Filtering by referenced entity requires ".uuid" to be specified in filter path expression, we attempted to match the structure of resource objects to acceptable filter paths. This meant that it became possible to filter by a resource object's ID using the id key (and not uuid) and also by an entity reference field's properties by prefixing it with meta.
The remaining disconnect is filtering by type. It's not technically a field on the underlying entity type so it fails to find a matching field. Unlike id, I (believe) we can't simply map the id field name to the bundle field name internally, because a resource type is both entity type + bundle specific.
Perhaps this is a moot point, because filters can only apply to one entity type at a given time (we throw an exception about its "ambiguous" nature if it doesn't).
Comments
Comment #2
wim leersExactly.
Until we support #2956414: Support mixed-bundle collections (e.g. `/jsonapi/node`), there's no point to this.
IMHO we should merge this into #2956414 and close it as a duplicate.
Comment #3
gabesulliceThat's not completely true. All
relatedroutes are already "mixed bundle collections", so, by extension, it's possible to have a filter across a relationship where the reference points to nodes, but you only want nodes of a certain bundle so you filter by type. Does that make sense?Comment #4
gabesulliceCurrently, you can do this by filtering by
?filter[field_node_ref.node_type.id]={article-uuid}, but I think the less leaky path would be?filter[field_node_ref.type]=node--articleComment #5
wim leersYou said "all"
relatedroutes, but I think you meant some (those forentity_referencefields that allow multiple target bundles). Nonetheless: GREAT point! 👏 I wish I'd thought of that! 😃I don't think that example has been brought up at #2956414: Support mixed-bundle collections (e.g. `/jsonapi/node`) yet, actually? I think that quite convincingly makes the case for mixed-bundle collections…
Comment #6
wim leersComment #7
effulgentsia commentedI'd personally consider this a bug rather than a feature request. The JSON:API spec considers both
idandtypeto be part of a resource's identification, so it seems very odd to be able to filter on one of those but not the other.Yes, I think that would be the natural syntax for it.
Comment #8
wim leersBut nothing in the JSON:API spec says you should be able to filter by every "JSON:API field".
Comment #9
effulgentsia commentedThe JSON:API spec doesn't dictate anything about filtering. But a filtering spec that allows you to filter on one member of a two-part identifier, but not on the other member, seems like a flawed spec, because it privileges one part of the identifier over the other.
Comment #10
wim leersSure. I’m not saying we should not do this. I’m saying this is less important than
id, could be added in any release without disruption.Nothing is broken; a capability is absent.
If you feel strongly this should be classified as a bug report, feel free to change it.
Comment #11
gabesulliceThe capability is present insofar as one is able to queryThat does match the JSON:API output structure though, so I don't think we need to qualify that as one of the recently discovered "leaky abstractions".?filter[field_node_ref.node_type.id]={node_bundle_uuid}.Edit: Actually, that's not possible, because a node bundle is a config entity, which is not queryable.
Comment #12
wim leersSo shall we in the mean time throw a 400 response if the user attempts to filter by
type?Comment #13
effulgentsia commentedNope. I believe the Fancy Filters spec is where the bug is. I think the spec should require being able to filter by
typeandid. My hope is that something like the Fancy Filters spec at some point gets some kind of formal approval by the json:api maintainers and increased adoption in the json:api community, and I think some more clarification and strictness about what it requires, allows, and does not allow, will be necessary for that. Of course, I might be wrong about all that. But in any case, based on the current spec, you are correct that Drupal's current implementation is not a bug.Comment #14
wim leersMakes sense, thanks!
Comment #15
gabesullice+1
Comment #16
rpayanmMoving to Drupal core's issue queue.
I'm working on https://www.drupal.org/project/drupal/issues/3122113