Graphql-engine: Allow query_by_pk style queries for unique constraints also

Created on 14 Feb 2019  路  7Comments  路  Source: hasura/graphql-engine

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.

server intermediate enhancement medium

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.

All 7 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jjangga0214 picture jjangga0214  路  3Comments

rikinsk-zz picture rikinsk-zz  路  3Comments

EmrysMyrddin picture EmrysMyrddin  路  3Comments

bogdansoare picture bogdansoare  路  3Comments

macalinao picture macalinao  路  3Comments