Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Unable to query nested relational content types #6

Closed
lucastobrazil opened this issue Sep 20, 2020 · 3 comments
Closed

Unable to query nested relational content types #6

lucastobrazil opened this issue Sep 20, 2020 · 3 comments
Assignees

Comments

@lucastobrazil
Copy link

lucastobrazil commented Sep 20, 2020

Love this starter, thank you for providing it! ❤️

I’m having an issue and not sure if it’s my understanding of Strapi/GraphQL or an issue.

Context: For my use case, I want to show a portfolio of projects (or 'cases'). Each case has a group of contributors that worked on it. This field is separate to the author. The issue is that for technical reasons, a Case's contents is split into two types: draft and published. Which means when I want to get all articles, I need to go one level 'deeper' in the nesting to also include the array of contributors.

Case
-- Draft
---- Caseinfo
------ Contributors

-- Published
---- CaseInfo
------ Contributors

Currently I can get allStrapiCase and get the contents of each case, plus its contributors:

// Used in Gatsby's `<StaticQuery />`
// This works fine.

  allStrapiCase {
    edges {
      node {
        contributors {
          name
        }
      }
    }
  }

But when I try to include the nesting

  allStrapiCase(filter: {status: {eq: "published"}}) {
    edges {
      node {
        published_contents {
          id
          title
          // Cannot query field "contributors" on type "StrapiCasePublished_contents".
          contributors {
              name
          }
        }
      }
    }
  }

So as soon as the contributors field is nested one level deeper, I cannot query it? Conceptually, can you make a deeply nested GraphQL query like this and expect it to follow all relational content types “down the tree”?

@lucastobrazil
Copy link
Author

Screenshot 2020-09-20 at 19 57 59

@markkaylor
Copy link
Contributor

Hi @lucastobrazil , I'm not sure I understand this query:

  allStrapiCase(filter: {status: {eq: "published"}}) {
    edges {
      node {
        published_contents {
          id
          title
          // Cannot query field "contributors" on type "StrapiCasePublished_contents".
          contributors {
              name
          }
        }
      }
    }
  }

Since you are filtering by status eq: published I would expect the query to return only cases with field status set to "published", for example:

Screenshot 2021-03-16 at 11 10 19

And if you wanted to query draft cases you could just do filter: {status: {eq: "draft"}}

@markkaylor markkaylor self-assigned this Mar 16, 2021
@markkaylor
Copy link
Contributor

@lucastobrazil I'm closing this issue, if my suggestions didn't help please feel free to re-open.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants