graphprotocol / graphprotocol/graph-node

Filtering for `null` nested entities

Aperta
#4,112 7 commenti 1 reazione 1 assegnatario Vedi su GitHub

@kamilkisiela ci sta già lavorando.

Dal 26/10/2022.

offchain
Lingua principale
Rust
Stelle
3.2k
Fork
1.1k
Merge medio
4g 1h
PR unite (30g)
1

Descrizione

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 }
}

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.