-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Closed
Labels
good first issueIssue that doesn't require previous experience with GatsbyIssue that doesn't require previous experience with Gatsbyhelp wantedIssue with a clear description that the community can help with.Issue with a clear description that the community can help with.type: documentationAn issue or pull request for improving or updating Gatsby's documentationAn issue or pull request for improving or updating Gatsby's documentation
Description
Preliminary Checks
- This issue is not a duplicate. Before opening a new issue, please search existing issues: https://github.com/gatsbyjs/gatsby/issues
- 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:
- docs: Document caveat of
@link
directive (by parameter) #25089 - Using createSchemaCustomization in gatsby-node to define reverse mapping defined in gatsby-config #25077
After looking into a custom createFieldExtension
, I discovered that elemMatch
works and subsequently found this:
#25336 (comment)
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 .
:
gatsby/packages/gatsby/src/schema/resolvers.ts
Lines 416 to 423 in 564a8f7
runQueryArgs.filter = options.by.split(`.`).reduceRight( | |
(acc: Record<string, any>, key: string) => { | |
const obj = {} | |
obj[key] = acc | |
return obj | |
}, | |
Array.isArray(fieldValue) ? { in: fieldValue } : { eq: fieldValue } | |
) |
Metadata
Metadata
Assignees
Labels
good first issueIssue that doesn't require previous experience with GatsbyIssue that doesn't require previous experience with Gatsbyhelp wantedIssue with a clear description that the community can help with.Issue with a clear description that the community can help with.type: documentationAn issue or pull request for improving or updating Gatsby's documentationAn issue or pull request for improving or updating Gatsby's documentation