graphile-contrib / postgraphile-plugin-connection-filter

Filtering on PostGraphile connections
MIT License
286 stars 32 forks source link

What is the corret way to use OR #9

Closed dallen66 closed 7 years ago

dallen66 commented 7 years ago

I am having an hard time getting OR to work. It is applying AND when I check the query executed SQL query.

query { allPosts( first: 10 filter: { or:{headline:{ilike: "%Mayer%"}} body:{ilike: "%Mayer%"}} ) { edges { node { id headline body } } } }

filter: { or:{headline:{ilike: "%Mayer%"}} body:{ilike: "%Mayer%"} } filter: { headline:{ilike: "%Mayer%"} or:{ body:{ilike: "%Mayer%"}} } filter: { or:{ headline:{ilike: "%Mayer%"} body:{ilike: "%Mayer%"}} }

This is what I am trying to accomplish. select post.* from forum_example.post as post where post.headline ilike ('%' || search || '%') or post.body ilike ('%' || search || '%')

mattbretl commented 7 years ago

or requires an array instead of an object. Try something like this:

{
  allPosts(first: 10, filter: {
    or: [
      { headline: { ilike: "%thing%"} },
      { body: { ilike: "%thing%"} }
    ]
  }) {
    edges {
      node {
        id
        headline
        body
      }
    }
  }
}

If run against kitchen-sink-schema.sql that query should return:

{
  "data": {
    "allPosts": {
      "edges": [
        {
          "node": {
            "id": 1,
            "headline": "No… It’s a thing; it’s like a plan, but with more greatness.",
            "body": null
          }
        }
      ]
    }
  }
}

Also, if you want to drop the % wildcards, you can use conti (containsInsensitive) to get the same result.

Let me know if you're still having trouble.

dallen66 commented 7 years ago

Thanks. Never thought of using and array, FACE-PALM. 😔