Um. How do we make a query that looks like below? ...
# orm-help
h
Um. How do we make a query that looks like below?
Copy code
{
        where: { id: userId },
        data: { friends:
          { connect:
             AND [
              { 
                id: friendId
              },
              NOT: { id: userId }
            ]
         } },
},
So that I don’t want to add current user as a friend inside the query.
d
@Hyo
Copy code
{
        where: { id: userId },
        data: { friends: { connect: { id: friendId } } },
}
does that not work? It should only connect whatever
id
matches
friendId
to the
friends
field.
k
If possible, I would move the conditional checks out of the query, so that you only execute query when
id !== userId
Maybe this helps? https://github.com/ounaturg/ounaturg-server/blob/master/src/resolvers/Listing.js#L149-L171
d
what @kuldar said, I wasnt thinking that you were trying to prevent
friendId === userId
h
@Daniel Mahon Yeah @kuldar <== he got my point. Well I know how to check that conditionally but I want to know how to achieve this in actual query.
Because in other case I might have some situations where I have to think of queries like that.
k
The easiest way is probably open Playground and check the available mutations/queries. It should give you a list of all the supported filter params. I think in this case you should use
id_not: …
instead of
NOT: { id: … }
but I need to check that real quick
Yup, so this sidebar in playground gives you a pretty good overview of the available queries and their formats.
❤️ 1
h
Awesome. Thanks I will check this out.
🙌 1