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.

Graphql AND/OR queries

default discord avatar
itspers2 years 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
    2 years 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
        }
      }
    }
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.