Using an 'or' in 'where' filter on graphQL queries

Hi there,

We have recently added a new boolean field to a document type and want to filter results based on that new field. The new field is set to default as 'false'. We are using where: { fieldProperty: false } to filter the response on the boolean added however some existing documents haven't defaulted to false but are returned as null.

We want all results that haven't explicitly been set to true to be returned but can't find a way to filter inline with an 'or' or 'not' within the filter - is there a way to do that? (Fetch Data with GraphQL - Documentation - Prismic)

At present it looks as though we may need to use two subqueries and combine the results returned which is less practical/neat. There are potentially a large number of existing documents (~900) so resolving the issue by individual documents will not be practical.

In summary: is there a way to add an or or not clause to a where: { } filter?

Thanks

Hello team.
The GraphQL endpoint doesn't have and OR operator option. What you can do is set false as the default option of your Boolean field

Hi, the default option in the boolean filed has not applied to all the documents the field is present on. As above, many of the documents are returned as null

This happens because there has been no change in the documents. As soon as you publish even a small change, the default value will appear in the field.

Thanks. It seems as though the vast majority of documents have updated the field to the default value without making any changes - is there any particular reason that some documents would be set with a default while others aren't?

Maybe there were some documents inside of a release? Publishing a batch of changes triggers the update of the field's default value.

As mentioned, we’ve been looking at ways to resolve the issue we’re having and merging separate queries isn’t an option as pagination will not work as we need it to.

Given the boolean field is returning three different possible values (true , false , or null ) it seems like we either need to 1) force all documents to update so they have a default value or 2) access two values in a single query.

As you have advised that there is no ‘or’ operator to go ahead with the second option can you please advise us how we can resolve this issue?

We have ~2k documents in total which need to be updated to only have a value of true or false and it would be too time-consuming to make these updates manually.

Unfortunately in this case, since the Boolean field was added after the initial content modeling of the Custom Type, there's no automatic option to update all documents, so a manual update is required.

I'll create a feature request to make this process easier.

Can you clarify how we can do this programmatically? (e.g. by forcing a re-publish of all documents of a type).

So, there isn't an automatic way of doing a lot of updating many docs at the same time. You need to manually trigger a change on each doc to see the changes reflected. The option would be to add them to a release as you go and then publish a large batch of changes just for this field.