graphprotocol / graphprotocol/graph-node

Filtering for `null` nested entities

Open
#4,112 7 comments 1 reaction 1 assignee View on GitHub

@kamilkisiela is already working on this.

Since Oct 26, 2022.

offchain
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 null applies 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.