Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[source-drupal] weird behaviour with Drupal entity references when inside a paragraph #19450

Closed
xaviemirmon opened this issue Nov 12, 2019 · 14 comments
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@xaviemirmon
Copy link
Contributor

Description

There's some strange behaviour happening with I use an entity reference inside a paragraph with Drupal. I can see the JSON:API is formatting everything as I expect. If I have an entity reference field on its own in a content type Gatsby can see the data and I am able to query values of the reference in my local GraphiQL instance. However, as soon as that is nested inside a reference it just returns NULL

I've created two fields within my "Page" content type.

Screenshot 2019-11-12 at 14 59 13

field_test — An entity reference field

field_test2 — A paragraph field (entity reference revisions). Inside that field, there is an entity reference field called field_embed which is identical to field_test

Screenshot 2019-11-12 at 15 00 03

On my content that I am querying, I've referenced the same content. "Travel tip-offs: the best places to visit in August" (Node 56 in Drupal)

Screenshot 2019-11-12 at 15 01 24

Steps to reproduce

Either use my site's data using the following in gatsby-config.js

resolve: `gatsby-source-drupal`,
      options: {
        baseUrl: `https://app.master-7rqtwti-shreqbivaapoy.eu-2.platformsh.site/`,
        preview: true,
        apiBase: `api`, // optional, defaults to `jsonapi`
    }

or

Add a paragraph field to your content type in Drupal and then add an entity reference field in that paragraph.

Next, running the following query in GraphiQL

query pageQuery($drupal_id: String) {
  nodePage(drupal_id: {eq: $drupal_id}) {
    relationships {
      field_test {
        title
        drupal_internal__nid
        drupal_id
      }
      field_test2 {
        relationships {
          field_embed {
            title
            drupal_id
            drupal_internal__nid
          }
        }
      }
    }
  }
}

Expected result

field_embed returns the same information as field_test

Actual result

field_embed is returning NULL

Screenshot 2019-11-12 at 15 13 06

Environment

System:
OS: macOS 10.15.1
CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Shell: 3.2.57 - /bin/bash

Binaries:
Node: 8.11.1 - /usr/local/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.12.1 - ~/.npm-packages/bin/npm
Languages:
Python: 2.7.15 - /usr/local/bin/python
Browsers:
Chrome: 78.0.3904.97
Firefox: 66.0.5
Safari: 13.0.3
npmPackages:
gatsby: ^2.17.2 => 2.17.2
gatsby-cli: ^2.8.5 => 2.8.5
gatsby-image: ^2.2.29 => 2.2.29
gatsby-plugin-manifest: ^2.2.23 => 2.2.23
gatsby-plugin-netlify-cache: ^1.2.0 => 1.2.0
gatsby-plugin-offline: ^2.2.10 => 2.2.10
gatsby-plugin-react-helmet: ^3.1.13 => 3.1.13
gatsby-plugin-sass: ^2.1.20 => 2.1.20
gatsby-plugin-sharp: ^2.2.32 => 2.2.32
gatsby-plugin-styled-components: ^3.1.11 => 3.1.11
gatsby-plugin-typography: ^2.3.15 => 2.3.15
gatsby-source-drupal: ^3.3.0 => 3.3.0
gatsby-source-filesystem: ^2.1.33 => 2.1.33
gatsby-transformer-sharp: ^2.3.0 => 2.3.0
npmGlobalPackages:
gatsby-cli: 2.8.0

@LekoArts LekoArts added the type: bug An issue or pull request relating to a bug in Gatsby label Nov 13, 2019
@shadcn
Copy link
Contributor

shadcn commented Nov 20, 2019

@xaviemirmon I think we're running into a similar issue with paragraph and entity references. Question: Is field_test2 a multi value or single value field?

It seems like this is failing for single value (cardinality: 1) fields.

@xaviemirmon
Copy link
Contributor Author

Ooh @arshad I think you are on to something here. The field itself is yes indeed a single value field. Nested inside a multivalue field. The non-nested field (field_test) is also a single value field though.

@shadcn
Copy link
Contributor

shadcn commented Nov 25, 2019

@xaviemirmon I found that if you change the following to relationships[nodeFieldName] = [referencedNodeId] it works.

relationships[nodeFieldName] = referencedNodeId

(This is a temporary fix while we figure out what's happening here)

@xaviemirmon
Copy link
Contributor Author

@arshad This is great! That makes it work! Does anyone know why this couldn't or shouldn't be done this way? Or shall I create a PR with this change?

@jonearley
Copy link

jonearley commented Nov 27, 2019

I also just ran into this issue and @arshad's suggested change resolved it.

@shadcn
Copy link
Contributor

shadcn commented Nov 27, 2019

@jonearley Nice. I created a PR so that we can get some feedback. #19844

@jonearley
Copy link

I suspect this would be a major version change for the plugin.

@shadcn
Copy link
Contributor

shadcn commented Nov 27, 2019

@jonearley Yeah let's see what breaks. Go CI :)

@xaviemirmon
Copy link
Contributor Author

Hey @arshad I found the one fatal flaw in the otherwise perfect plan. 😬 When adding this bit of code, my site broke because multiple nested relationships started having an extra [0] key in the array e.g. field_example[0] This makes it a breaking change. That said I was thinking if we can find the items with a single cardinality later on in the code, we could probably just wrap that in an array to get working for both scenarios.

@jonearley
Copy link

jonearley commented Dec 3, 2019

The plugin behaves as if the entity reference will only be of one type and doesn't account for an entity reference to multiple Drupal content types.

This bug blocks my work at the moment. I am considering forking and using the [] change for now until the plugin has an official fix.

@vladar
Copy link
Contributor

vladar commented Dec 5, 2019

It sounds like a duplicate of #10090 and could be potentially fixed in #19916 (should be published in gatsby 2.18.7)

@shadcn
Copy link
Contributor

shadcn commented Dec 5, 2019

Thanks @vladar I'll test this.

@shadcn
Copy link
Contributor

shadcn commented Dec 5, 2019

@vladar Bingo! 2.18.7 (#19916) fixed this. Thanks so much 👍

@vladar
Copy link
Contributor

vladar commented Dec 5, 2019

Great. Glad it helped!

@vladar vladar closed this as completed Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants