graphprotocol / graphprotocol/graph-node
Filtering for `null` nested entities
@kamilkisiela is already working on this.
Since Oct 26, 2022.
- Dominant language
- Rust
- Stars
- 3.2k
- Forks
- 1.1k
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 1
Description
Given the following schema:
type BadgeSpec @entity {
id: String!
metadata: SpecMetadata
}
type SpecMetadata @entity {
id: ID!
name: String!
}
The BadgeSpec metadata field is populated with the ID of a SpecMetadata entity. At query time, that is used as a lookup to return a SpecMetadata entity, if there is one with a matching ID. If there is no matching ID, the metadata object returns as null.
Users might want to filter for BadgeSpecs with no connected metadata, and might expect the following query to do that:
{
badgeSpecs(where: {metadata: null}) {
id
metadata {
id
name
}
}
}
However that is not necessarily the current behaviour - filtering badgeSpecs on metadata filters on the value of the metadata field. So if the field is populated with an ID, but there isn't a SpecMetadata entity with that ID, then that BadgeSpec will not be returned. BadgeSpecs will only be returned when the value of the metadata field is itself null. There is currently no way to filter for all badgeSpecs with no connected metadata, regardless of whether the metadata field is populated.
Potential solutions:
- Update functionality for nested entities such that the filter reflects the nested entity's ID, so that
nullapplies where entities are not found. This is a change in behaviour, so raises the question: are there valid cases where users wouldn't expect filtering to work in this way? - Update nested filter functionality to filter for "null" IDs, i.e.
badgeSpecs(where: {metadata_: {id: null}}) {
id
metadata { id }
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.