Entity Reference Fields should only return enabled entities

Created on 11 June 2023, over 1 year ago
Updated 19 June 2023, over 1 year ago

Just wondering if there's any plans to resolve the following.

Problem/Motivation

At the moment entity reference fields return all possible entity type even if they are not enable. For example a paragraph field will show all the paragraph that have been enabled in the config even if only a select few are enabled on the field.

This means that when viewing in explorer it misleading as to what can actually be returned and frontend experience isn't ideal.

Proposed resolution

Entity reference fields should only return enabled bundles.

📌 Task
Status

Fixed

Version

2.0

Component

Code

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

Comments & Activities

  • Issue created by @marcus.williams
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    I guess the alternative is creating dynamic unions for each reference field, which adds a heap of new non-reusable unions to the schema. It's possible, and it's how it started out working.

    But I err'd on the side of less schema vs more types.
    Basically you just end up with a heap of... {Node}{Page}{Fieldname}Union with the types allowed.

    It would now be a considerable shift in functionality, but what I can do is explore re-adding it and making it opt-in, as I totally understand the request.

  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Ok, heres your proof of concept.

    https://git.drupalcode.org/issue/graphql_compose-3366088/-/commit/0be592...

    If this is what you're thinking, we just have to figure out a nice way to integrate it without messing people around with a major schema change.

  • Thanks for the update, I'll try and have a look at it as soon as I can. If it's opt in surely that would mean it wouldn't affect anyone who uses it as it currently is unless I'm missing something.

  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Yeah leave it with me for the night, I'll grab a glass of wine and have a stab at it the UI side in a few hours.

  • @almunnings opened merge request.
  • Assigned to almunnings
  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Ok, took a couple glasses. Got there.

    Have a play with the MR if you can, see how that works for you.

    Note: This is in line with 2-dev and will require a drush updatedb, so, uh, test accordingly.

  • This looks amazing, thanks for the quick response and looks like it's exactly what I was after. The only thing I'm unsure on is what it should do if there's only a single entity enabled i.e should it be

              teaser {
                ... on ParagraphTeaser {
                  id
                }
              }
    

    or should it just return

              teaser {
                 id
              }
    
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Yep I got ya.

    It would mean your entity will return a new type on config change...

    Single entity ref = single return type
    Multiple entity ref = union return type

    Which could affect your frontend implementation - but you gotta risk it for the biscuit.

    I'll push up a change now for you to play with.

  • Yes that's perfect, many thanks for that

  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Cool stuff. I’ll wrote a test with some more wine and merge to dev for next release

  • Status changed to Fixed over 1 year ago
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Ok, all done, in dev.

    Thank you for shopping with us.

  • Status changed to Fixed over 1 year ago
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺
Production build 0.71.5 2024