Skip to content

Commit f595257

Browse files
aryans1319renovate[bot]LekoArts
authored
chore(docs): Example @link directive with array (by elemMatch) (#36632)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Lennart <lekoarts@gmail.com> Fixes #36330
1 parent 4083249 commit f595257

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs/docs/reference/graphql-data-layer/schema-customization.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,17 @@ In other words, you `link` **on** `from` **to** `by`. This makes `from` especial
459459

460460
For the above example you can read `@link` this way: Use the value from the field `Frontmatter.reviewers` and match it by the field `AuthorJson.email`.
461461

462-
Keep in mind that in the example above, the link of `posts` in `AuthorJson` works because `frontmatter` and `author` are both objects. If, for example, the `Frontmatter` type had a list of `authors` instead (`frontmatter.authors.email`), it wouldn't work since the `by` argument doesn't support arrays. In that case, you'd have to provide a custom resolver with [Gatsby Type Builders](/docs/reference/graphql-data-layer/schema-customization/#gatsby-type-builders) or [createResolvers API](/docs/reference/graphql-data-layer/schema-customization/#createresolvers-api).
462+
Keep in mind that in the example above, the link of `posts` in `AuthorJson` works by defining a path to a node because `frontmatter` and `author` are both objects. If, for example, the `Frontmatter` type had a list of `authors` instead (`frontmatter.authors.email`), you would need to define it like this with [`elemMatch`](/docs/graphql-reference/#filter):
463+
464+
```graphql
465+
type AuthorJson implements Node {
466+
# Using .elemMatch is important here
467+
posts: [MarkdownRemark]
468+
@link(by: "frontmatter.authors.elemMatch.email", from: "email")
469+
}
470+
```
471+
472+
You can also provide a custom resolver with [Gatsby Type Builders](/docs/reference/graphql-data-layer/schema-customization/#gatsby-type-builders) or [createResolvers API](/docs/reference/graphql-data-layer/schema-customization/#createresolvers-api) to link arrays.
463473

464474
### Extensions and directives
465475

0 commit comments

Comments
 (0)