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

Pull in nested entities when using Gatsby Drupal plugin #6172

Closed
sheelah opened this issue Jun 26, 2018 · 9 comments
Closed

Pull in nested entities when using Gatsby Drupal plugin #6172

sheelah opened this issue Jun 26, 2018 · 9 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@sheelah
Copy link
Contributor

sheelah commented Jun 26, 2018

Is it possible to customize the data pulled in from a Drupal 8 JSON API by the Gatsby Drupal plugin? It's working fine for basic queries, but I'm noticing that it doesn't pull in all nested relationship data for my content types.

For example, if I have showcase content type, I can pull in any showcase's information, but the child showcase items are not getting included:

{
  showcase(nid: {eq: 19389}) {
    id
    uuid
    title
    description
    nid
    description
    children {
      id
    }
  }
}

I get back data with children being empty, instead of including the nested relationships data:

{
  "data": {
    "showcase": {
      "id": "6696c92f-b059-4a26-8bc7-c522b267ec46",
      "uuid": "6696c92f-b059-4a26-8bc7-c522b267ec46",
      "title": "Showcase Contact Us",
      "description": "Holla.",
      "nid": 19389,
      "children": []
    }
  }
}

If I query my Drupal 8 JSON API directly I can see the showcase's relationship data:

{
    "data": [
        {
            "type": "showcase",
            "id": "6696c92f-b059-4a26-8bc7-c522b267ec46",
            "attributes": {
                "nid": 19389,
                "uuid": "6696c92f-b059-4a26-8bc7-c522b267ec46",
                "vid": 102223,
                "langcode": "en",
                "status": true,
                "title": "Showcase Contact Us",
                "created": 1529948819,
                "changed": 1529948935,
                "path": null,
                "description": "Holla."
            },
            "relationships": {
                "items": {
                    "data": [
                        {
                            "type": "showcase_item",
                            "id": "e7d9cc10-d606-4801-81a7-94aaf94ebc64",
                            "meta": {
                                "target_revision_id": 43
                            }
                        },
                        {
                            "type": "showcase_item",
                            "id": "3d6b19ee-500b-4ca5-9774-2c3229170414",
                            "meta": {
                                "target_revision_id": 44
                            }
                        }

Is there something I should be customizing via gatsby-node.js, or would I need to recreate this plugin with more customizations? Thanks!

@KyleAMathews
Copy link
Contributor

What is the full schema for showcase? You can see this in graphiql in the docs explorer.

@m-allanson m-allanson added the type: question or discussion Issue discussing or asking a question about Gatsby label Jun 27, 2018
@sheelah
Copy link
Contributor Author

sheelah commented Jun 27, 2018

The schema for showcase that the Gatsby Drupal plugin is creating:
gatsby_drupal_plugin_showcase_schema

Here's the underlying Drupal 8 schema for showcase:
drupal8_schema_showcase

Here's the schema for showcase fieldItems which are the child items that are not coming through in Gatsby when using the Drupal plugin:
drupal8_schema_showcase_items

@pieh
Copy link
Contributor

pieh commented Jun 28, 2018

Hey, drupal plugin currently doesn't support 1 to many relationships - there is open PR to fix that - #5020 but I didn't have time to update it lately. If you feel like you could take that over, fix merge conflicts this could be merged to master because we are developing beta versions of packages, so it's OK-ish to land breaking stuff now

@sheelah
Copy link
Contributor Author

sheelah commented Jun 28, 2018

Thanks @pieh - wasn't aware of that. I'm a bit unclear on what's remaining on #5020 -- just merge conflict fixes, or implementation of that second piece that was being discussed (naming of back-references)?

@pieh
Copy link
Contributor

pieh commented Jun 28, 2018

Just merge conflicts for now would be fine. Other things mentioned in that PR could be done later if needed.

I still think that my point about not using type names as field names for back-references is valid (using same example scenario I presented in that PR), but this could be done with non-breaking change later - for example by using both type names (as we do right now) and additionally backref_${relationship_name} (or however that would be called).

@sheelah
Copy link
Contributor Author

sheelah commented Jun 28, 2018

I see. Was the plan to still merge this into the master branch (which is now defaulting to Gatsby v2), or the v1 branch?

I tried this branch out and am seeing relationship data coming through 🎉 but I'm getting some GraphQL schema-related errors when trying to pull in some of the child entities' fields (Ex. "message": "Expected value of type \"press\" but got: [object Object].",) so I'm thinking that with all its nested relationships, my use case may require a custom plugin altogether.

@pieh
Copy link
Contributor

pieh commented Jun 28, 2018

hmm, I might missdiagnoses earlier then, but still I feel like default plugin could be adjusted to handle those too

@sheelah
Copy link
Contributor Author

sheelah commented Jul 12, 2018

That was the correct diagnosis. Update on this one: my team has opted to build a custom GraphQL-based plugin instead, so I'm not going to be able to contribute to #5020. Happy to open a PR to add a note about the current Gatsby Drupal source plugin limitations in its readme if you'd like though.

@KyleAMathews
Copy link
Contributor

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

4 participants