Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Where clause in GraphQL query does not work on fallbackLocale

default discord avatar
STR1234last year
1 1

Link to reproduction

No response

Describe the Bug

When having a GraphQL Query that has a fallbackLocale specified and using a where clause to filter for specific checkbox value (in this case) the where selector does not work properly on the specified fallbackLocale.

		fallbackLocale: en_DE
		limit: 500
		where: { showInOverview: { equals: true } }

Here I fallback to a locale where at least one document has the showInOverview value set to true. When querying directly for the locale en_DE this does indeed deliver the proper results.
When querying for a locale that does not yet have any data and falling back to en_DE the where operation has the consequence that no documents are found. When removing the where clause the expected data from the en_DE fallback locale is delivered.

To Reproduce

  1. Have a document with a field (textfield, checkbox or something that makes for an easy where selection) that has localized set to true and another field (like a text field) also with localized set to true just for content.
  2. Have at least two locales configured and for one of them the document has data (fields are filled out), for the other it does not.
  3. Specify the GraphQL query to fallback to the locale where data was entered.
  4. Query for the document with the locale that does not have data, also specifying that one of the documents fields needs to have a certain value with the where clause (easiest would be a checkbox boolean value like in my case).
  5. Even though the document in the fallback locale contains the appropriate value no documents are returned.

After further investigation: (edited the reproduction steps as well)
I found that for a slug text field that I have in the document it works properly but with another title text field it does not work.

The only difference between the fields:
The title is required and localized. The slug is neither.
The showInOverview field is also localized and required. This might have something to do with the fact that the field I select for in the query is localized 🤔 (I would suspect that rather than the required prop)

Payload Version

2.13.0

Adapters and Plugins

db-mongodb, bundler-webpack, plugin-cloud-storage, richtext-lexical, translator-plugin

  • Selected Answer
    discord user avatar
    jmikrut
    last year

    Hey @STR1234 — this is expected actually. We can't query for multiple locales at once because that would require some performance overhead. We only query in the locale that you have specified (or the default locale).

    You might want to find another pattern if you will be querying on this field often. Maybe specify the field separately once per locale?

    1 reply
  • default discord avatar
    STR1234last year

    Thank you @jmikrut for the clarification 🙌 I will look into another pattern but intuitively I expect a different behaviour - maybe I can propose additions to the documentation to make the expected behaviour clearer or I might have missed something in the docs that already explains this.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.