Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Semantics of how the or operator should be used #2009

Closed
craicoverflow opened this issue Sep 7, 2020 · 5 comments · Fixed by #2034
Closed

Semantics of how the or operator should be used #2009

craicoverflow opened this issue Sep 7, 2020 · 5 comments · Fixed by #2034
Assignees
Labels

Comments

@craicoverflow
Copy link

  • Module: @graphback/runtime-mongodb, @graphback/runtime-knex
  • Version: *
  • Node.js / npm versions: NA

When combined with the root query operators, the or operator evaluates to find X where <root query conditions> OR <or conditions>. Take the example below. This outputs the following pseudo-query in both Postgres and MongoDB: find Blogs where name is "blog3" or name is "blog3" or condition3....

{
  findBlogs(filter: {name: {eq: "blog3"}, or: [{name: {eq: "blog1"}}]}) {
    items {
      id
      name
    }
  }
}

Upon initial raising of this as being potentially incorrect by @machi1990 and then checking out alternative libraries (namely AWS AppSync), the query above should output: find Blogs where name is "blog3" and (name is "blog3" || condition2 || condition 3)...

@craicoverflow craicoverflow added the bug Something isn't working label Sep 7, 2020
@machi1990
Copy link
Contributor

Automatically generated comment to notify maintainers
/cc @machi1990, @wtrocki

@craicoverflow
Copy link
Author

Thanks for highlighting this one @machi1990 - this is in fact a bug and should be actioned ASAP.

@craicoverflow
Copy link
Author

Going to start this.

@machi1990
Copy link
Contributor

Thanks @craicoverflow

@CoreyKovalik
Copy link
Collaborator

This should be re-opened, as I believe there are still bugs in the knex query builder. We are experiencing that this simply does not work as expected for Postgres + Knex for any and/or query on the same field.

Example:

// returns no results
query {
  findLocations (filter: { country_code: { eq: "US" }, or: { country_code: { eq: "CN" } } })
  
// the following 2 queries seem to work as expected, and return different results....
query {
  findLocations (filter: { country_code: { eq: "US" }, or: { city: { contains: "a" } } })

query {
  findLocations (filter: { country_code: { eq: "CN" }, or: { city: { contains: "a" } } })
  
// However, `or` seems to be operate no different than `and`.
// Expected: locations return with Either `country_code` === "US" or countries starting with `C`, i.e. `China`
// Actual: No results, assuming because "United States" doesn't have "C"
findLocations (filter: { country_code: { eq: "US" }, or: { country_name: { contains: "C" } } }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants