Graphql AND/OR queries

default discord avatar
itspers
5 months ago
1

Here it has example



https://payloadcms.com/docs/queries/overview#and-or-logic

And then in

https://payloadcms.com/docs/queries/overview#graphql-find-queries

it says



"All GraphQL find queries support the where argument, which accepts queries exactly as detailed above."



But in grapql types it has just XXX_where_or and XXX_where_and, which are just same as XXX_where



How to search for blog posts like "_status: {equals: pubslihed} , category: {equals: 'xxx'} AND (title: {contains: 'term'} OR body: {contains: 'term'})"?

  • discord user avatar
    jacobsfletch
    Payload Team
    5 months ago

    @itspers have you seen the GraphQL Playground yet? You can go to

    /api/graphql-playground

    and see full docs into your schema and API, details here

    https://payloadcms.com/docs/graphql/overview#graphql-playground

    . Looking in the playground I can see that the

    where

    argument can contain the

    OR

    and

    AND

    properties. So your example should look something more like this:



    query Page($category: String, $term: String) {
      Pages(where: { AND: { _status: { equals: published }, category: { equals: $category }}, OR: { title: { contains: $term }, body: { contains: $term } }})  {
        docs {
          id
        }
      }
    }
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.