Skip to content

Ability to access reverse relations within entry query in GQL #7110

Closed

Description

@andrewfairlie

It would be really useful if when querying entries in GraphQL you could get reverse related elements to that entry, which would avoid you having to do multiple GraphQL calls of "get the entry ID, and then run another GraphQL query with relatedTo() because this can quickly add up and become clunky.

Original comment from other thread

Just a thought, and apologies if this was covered in other thoughts above and I misunderstood, would a good syntax for this be something like relatedEntries, relatedAssets etc. which behave like a normal entries / asset loop but with the relatedTo pre-populated with the current entry. So you could do things like this very weird, but hopefully useful example...?

entry(section:"offices",slug:"london"){
   title,
   id,
   ... on offices_offices_entry {
      peopleInThisOffice: relatedEntries(section:"people"){
        title
      }
      facilitiesInThisOffice: relatedEntries(section:"facilities"){
        title
      }
      imagesTaggedInThisOffice: relatedAssets(source:"images"){
        title
      }
   }
}

Originally posted by @andrewfairlie in #5143 (comment)

Activity

  1. added a commit that references this issue on Nov 27, 2020
    6ebde15
  2. andris-sevcenko commented on Nov 27, 2020

    @andris-sevcenko
    Contributor

    This has been added for Craft 3.6

  3. andris-sevcenko commented on Nov 27, 2020

    @andris-sevcenko
    Contributor

    Well, in its own branch for now.

  4. added a commit that references this issue on Dec 2, 2020
    e0c0d79
  5. brandonkelly commented on Dec 2, 2020

    @brandonkelly
    Member

    Merged now. Note that it’s relatedToEntries, etc., not relatedEntries.

  6. brandonkelly commented on Dec 15, 2020

    @brandonkelly
    Member

    Craft 3.6 RC2 is out now with these new GraphQL arguments.

  7. brandonkelly commented on Jan 27, 2021

    @brandonkelly
    Member

    Craft 3.6 has now been officially released ✨

  8. membla commented on Feb 22, 2021

    @membla

    Just had a conversation on Discord with @andris-sevcenko on this – the actual issue at hand here is not resolved and even if it may not be feasible to do it in the GraphQL API without changes to the Element Query API or Element itself I think the issue should be reopened because the use case is very valid (and well explained in the original post above).

  9. added this to the milestone on Feb 23, 2021
  10. brandonkelly commented on Feb 23, 2021

    @brandonkelly
    Member

    Whoops, you’re right @membla. Guess we were on a different brainwave. We’re considering how to best address this.

  11. locked and limited conversation to collaborators on Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementimprovements to existing featuresgraphql ⚙️features related to the GraphQL API

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions