GraphQL query for MatrixFields #11511
-
Is it possible to query for matrixfields using GraphQL? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
It’s not. You should be able to accomplish what you want using the Preparse Field plugin, which can be used to store prerendered values as top-level fields. So for example if you want to filter entries in GraphQL if any of its Matrix blocks contain a certain value, you could set the Preparse field to: {{ clone(element.myMatrixField)
.someField('test-value')
.exists() ? '1' }} Then in your GraphQL query, you could include |
Beta Was this translation helpful? Give feedback.
-
Thanks but that won't work for me because i am using the CMS in headless mode. |
Beta Was this translation helpful? Give feedback.
-
If you just want your Matrix content to be treated as search keywords for the entries, that’s possible out of the box. Edit your Matrix field, and ensure it’s “Use this field’s values as search keywords” checkbox is ticked. Then do the same for each sub-field that you want included in the Matrix field’s search keywords. Finally, run the following command for any sections that use the Matrix field: php craft resave/entries --section <sectionHandle> --update-search-index Once finished, the |
Beta Was this translation helpful? Give feedback.
-
@brandonkelly would this technique work for entry fields nested within a matrix block? |
Beta Was this translation helpful? Give feedback.
If you just want your Matrix content to be treated as search keywords for the entries, that’s possible out of the box.
Edit your Matrix field, and ensure it’s “Use this field’s values as search keywords” checkbox is ticked.
Then do the same for each sub-field that you want included in the Matrix field’s search keywords.
Finally, run the following command for any sections that use the Matrix field:
Once finished, the
search
GraphQL query argument will work for your Matrix fields.