Hi,
I set multiple primary key for user table (id and email) I want to query user_by_pk with either id or email but when I tried I found that the schema require both of the primary columns values to query, it should allow query with one key only.
@alaarihan A multiple primary key is not 2 primary keys, but it's that the combination of (id, email) is a primary key.
I think what you were looking for is making id a primary key, and email a unique index!
@coco98 I just want to query a single item with one parameter just like Prisma, I need to query by id or email (in Prisma I just make id and email fields as unique)
@alaarihan The easiest way to do this right now is:
query {
user (where: {email: {_eq: "xx"}}) {
id
email
}
}
You'll get a list and you'll have to do get the first element from the result. (Just like you'll have to check to see if the result is null if you'd received a single object in a by_pk kind of query).
Although, making it easy to query single objects might be a nice feature to add to the by_pk style querying! @0x777 @rakeshkky Any thoughts on querying single items by a unique constraint?
Yes I did it this way for now but I just thought it will be great if we can query a single item by any unique field in the table.
@alaarihan Sounds like a great idea! Let's see what @0x777 @rakeshkky say :)
Closing this in favour of #519.
Most helpful comment
Yes I did it this way for now but I just thought it will be great if we can query a single item by any unique field in the table.