0

I have a "users" table that is connected to "interestTags" table. I would like to be able to search users interestTags and return all users that match one or more tags, In this example I would like to be able to return all users that has interestTags of either "dog" or "apple.

The code below is only showing matches for "apple" and leaving out the "dog" interestTag users. I would like to get both "dog" users and "apple" users returned instead of one or the other. How would I go about doing this? Here is my code:

  users(offset: $offset, limit: 30, order_by: {lastRequest: asc}, where: {dob: {_gte: $fromDate, _lte: $toDate}, interestTagsFromSenderId: {_or: [{tag: $tagList}]}}) {
    id
    displayName
    profilePhotoUrl
    dob
    bio
    location
    interestTags: interestTagsFromSenderId {
      tag
    }
    created_at
  }
}

graphql query variables:

{
  "offset": 0,
  "fromDate": "1999-07-01",
  "toDate":  "2024-01-01", 
  "tagList": 
   {
     "_eq": "dog", "_eq": "apple"
   }
}

This is what graphql is returning:

{
  "data": {
    "users": [
      {
        "id": 31,
        "displayName": "n00b account",
        "profilePhotoUrl": "default.jpg",
        "dob": "2021-07-15",
        "bio": null,
        "location": null,
        "interestTags": [
          {
            "tag": "apple"
          }
        ],
        "created_at": "2021-07-15T06:57:23.068243+00:00"
      }
    ]
  }
}
  • passing object with two ``_eq`` doesn't make sense (overwritten prop) ... pass entire `$where` because no logic possible in [query only] assigning vars (by existence) – xadm Jul 20 '21 at 07:27
  • ah gotcha, okay. after rethinking what you wrote, i was able to fix it. i added ```$tagList: [interestTags_bool_exp!]``` to the query function and I changed the query to ```interestTagsFromSenderId: {_or: $tagList}}``` and the variable query to ```{ "tagList": [{"tag": {"_eq": "dog"}}, {"tag": {"_eq": "apple"}}]}``` – Matthew Slaton Jul 20 '21 at 18:48
  • @MatthewSlaton you can post and accept your own answer. It's encouraged on SO – Alex Yu Jul 31 '21 at 07:39

1 Answers1

0

to fix the issue:

  1. I added $tagList: [interestTags_bool_exp!] to the query function
  2. I changed the query to interestTagsFromSenderId: {_or: $tagList}}
  3. And changed the variable query to { "tagList": [{"tag": {"_eq": "dog"}}, {"tag": {"_eq": "apple"}}]}
Dharman
  • 30,962
  • 25
  • 85
  • 135