Reverse Entity Lookup

Created on 6 April 2023, over 1 year ago
Updated 25 January 2024, 8 months ago

Problem/Motivation

We are upgrading to graphql v4. We are currently using large queries that include reverse entity lookup:

reverseFieldOfficeNode(
    filter: {conditions: [{field: "type", value: "news_story"}, {field: "status", value: "1"}, {field: "field_featured", value: "1"}]}
    sort: {field: "created", direction: DESC}
    limit: 2
  ) {
    entities: items {
      id

Steps to reproduce

Proposed resolution

Provide an extension that supports reverse entity lookup. We are happy to support.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States edmund.dunn Olympia, WA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @edmund.dunn
  • Status changed to Postponed over 1 year ago
  • πŸ‡¨πŸ‡­Switzerland ayalon

    For the moment we have other priorities on our projects that we have to implement first.

    But we happily accept your patch or merge request. It should be fairly easy to write an extension and generate the related missing reverse entity lookups.

  • πŸ‡¨πŸ‡­Switzerland dulnan

    I gave this a try and it was pretty straight forward. I didn't want to make it work like in V3, because that created tons of overly specific fields (I counted 460 fields in one of our projects still using V3...)

    Instead there is only a single field added to each entity type called *reverseReferences*. It returns a type called *ReverseReferenceContext* where a field *query* is available. This query field takes a parameter called *referenceFields*, where one can specify which fields should be used to look for references. This also allows to create reusable fragments for such reverse lookups.

    query {
      entityById(entityType: TAXONOMY_TERM, id: 123) {
        reverseReferences {
          ...reverseOfficeLookup
        }
      }
    }
    
    fragment reverseOfficeLookup on ReverseReferenceContext {
      query(
        referenceFields: ["field_office"]
        entityType: NODE
        filter: {
          conditions: [
            { field: "type", value: "news_story" }
            { field: "status", value: "1" }
            { field: "field_featured", value: "1" }
          ]
        }
        sort: { field: "created", direction: DESC }
        limit: 2
      ) {
        entities: items {
          id
        }
      }
    }
    

    This new schema extension is available in the dev branch.

  • Status changed to Fixed 8 months ago
  • πŸ‡¨πŸ‡­Switzerland ayalon
  • πŸ‡¨πŸ‡­Switzerland ayalon

    The feature is part of the current release.

  • Status changed to Fixed 8 months ago
  • πŸ‡¨πŸ‡­Switzerland ayalon
Production build 0.71.5 2024