Graphql-engine: query with multiple _in's executed with OR

Created on 29 Dec 2018  路  2Comments  路  Source: hasura/graphql-engine

query message_thread ($firstUserId: Int!, $secondUserId: Int!) {
        message_thread(
          where: {first_user_id: {_in: [$firstUserId, $secondUserId]},
            second_user_id: {_in: [$secondUserId, $firstUserId]}
          }
        ) {
          id
          first_user_id
          second_user_id
        }
      }

query like this treats two _in conditions with OR top level

screenshot from 2018-12-29 17-16-16
screenshot from 2018-12-29 17-16-12

Most helpful comment

for record _or operator can be used to the top level to connect all WHERE fields by OR

{
where: {_or: [
{..},
{..}
]}
}

All 2 comments

@moksahero Fields at the top level are combined with an SQL AND. If you need an OR behavior, you'll need to use _or operator.

For example, query such as this:

query {
  tracks(where: {
    id: {_in: [1,2]}
    album_id: {_in: [1,2]}
  }) {
    id
    album_id
  }
}

gets converted into

SELECT
  coalesce(json_agg("root"), '[]') AS "root"
FROM
  (
    SELECT
      row_to_json(
        (
          SELECT
            "_1_e"
          FROM
            (
              SELECT
                "_0_root.base"."id" AS "id",
                "_0_root.base"."album_id" AS "album_id"
            ) AS "_1_e"
        )
      ) AS "root"
    FROM
      (
        SELECT
          *
        FROM
          "public"."tracks"
        WHERE
          (
            (
              ("public"."tracks"."id") IN (('1') :: integer, ('2') :: integer)
            )
            AND (
              ("public"."tracks"."album_id") IN (('1') :: integer, ('2') :: integer)
            )
          )
      ) AS "_0_root.base"
  ) AS "_2_root"

You can see that the conditions are ANDed.

for record _or operator can be used to the top level to connect all WHERE fields by OR

{
where: {_or: [
{..},
{..}
]}
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hooopo picture hooopo  路  3Comments

jjangga0214 picture jjangga0214  路  3Comments

sachaarbonel picture sachaarbonel  路  3Comments

anisjonischkeit picture anisjonischkeit  路  3Comments

stereobooster picture stereobooster  路  3Comments