gatsby icon indicating copy to clipboard operation
gatsby copied to clipboard

docs: Example @link directive with array (by elemMatch)

Open cpboyd opened this issue 2 years ago • 5 comments

Preliminary Checks

  • [X] This issue is not a duplicate. Before opening a new issue, please search existing issues: https://github.com/gatsbyjs/gatsby/issues
  • [X] This issue is not a question, feature request, RFC, or anything other than a bug report. Please post those things in GitHub Discussions: https://github.com/gatsbyjs/gatsby/discussions

Summary

Previous issues:

  • #25089
  • #25077

After looking into a custom createFieldExtension , I discovered that elemMatch works and subsequently found this: https://github.com/gatsbyjs/gatsby/issues/25336#issuecomment-652276026

Steps to Resolve this Issue

The docs should clarify that this works:

type Author implements Node {
  id: ID!
  name: String!
  email: String!
- posts: [Post!]! @link(from: "email", by: "authors.email")
+ posts: [Post!]! @link(from: "email", by: "authors.elemMatch.email")
}

type Post implements Node {
  id: ID!
  title: String!
  body: String!
  authors: [Author!]! @link(by: "email")
  tags: [Tag!]! @link
}

type Tag implements Node {
  id: ID!
  label: String!
  description: String!
- posts: [Post!]! @link(from: "id", by: "tags.id")
+ posts: [Post!]! @link(from: "id", by: "tags.elemMatch.id")
}

This works because how the query is formed by splitting on .: https://github.com/gatsbyjs/gatsby/blob/564a8f7358edd2599199e79c902468fa83f916b2/packages/gatsby/src/schema/resolvers.ts#L416-L423

cpboyd avatar Aug 06 '22 21:08 cpboyd

Happy to review a PR changing this!

https://www.gatsbyjs.com/contributing/how-to-open-a-pull-request/

LekoArts avatar Aug 08 '22 10:08 LekoArts

Can I work on this issue @LekoArts ?

aryans1319 avatar Aug 18 '22 13:08 aryans1319

Absolutely @aryans1319! Feel free to jump on this.

marvinjude avatar Sep 05 '22 08:09 marvinjude

Can you assign this to me?

aryans1319 avatar Sep 05 '22 09:09 aryans1319

Sure thing 👍

marvinjude avatar Sep 06 '22 11:09 marvinjude

Hi @cpboyd @LekoArts , I'm interested in above task, can you pls let me know whether the above task is still open.

kachida avatar Nov 21 '22 14:11 kachida