Skip to content

fix(gatsby): Add early return in link resolver for empty arrays #20068

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

Merged
merged 1 commit into from
Dec 11, 2019

Conversation

sidharthachatterjee
Copy link
Contributor

@sidharthachatterjee sidharthachatterjee commented Dec 11, 2019

Why

Consider a schema like,

type Item {
  name: String
}

type Collection {
  items: [Item]! @link(by: "id", from: "items___NODE")
}

And a query like,

allCollection {
  nodes {
    items {
      name
    }
  }
}

If a collection has no items, this currently returns items set to null as opposed to [] (even if it is non nullable as shown in the schema above).

Why

This happens because the link resolver sets the { in: value } operator in case the field value is an array. This however doesn't make sense for an empty array.

This PR adds an early return to fix this 🙂

Todo

  • I'd like to add a test for this but unsure where a test for this should go?

Related issues

@Simply007 discovered this issue when building gatsby-source-kentico. You can find a reproduction at https://github.com/Simply007/gatsby-null-instead-of-array

@sidharthachatterjee sidharthachatterjee requested a review from a team as a code owner December 11, 2019 12:27
@sidharthachatterjee sidharthachatterjee added the type: bug An issue or pull request relating to a bug in Gatsby label Dec 11, 2019
@sidharthachatterjee sidharthachatterjee added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Dec 11, 2019
@gatsbybot gatsbybot merged commit 3e2ad17 into master Dec 11, 2019
@delete-merged-branch delete-merged-branch bot deleted the fix-empty-array-for-link branch December 11, 2019 12:53
@sidharthachatterjee
Copy link
Contributor Author

Published in [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants