简体   繁体   中英

Hasura Graphql- How to pass Output of one Query as an input to the other Query?

I am new to Postgres DB and Hasura-Graphql. It would be good if anyone can help me out.

So there are two tables, Table1 with( username, email, id, table1id) and Table2 with (username, email, booksRead, visitedLocations, table2_id). These two tables are not connected( either by PK or FK).

Now the question is I have to query from table1 to get uername and email with that I need to query table2. So is there anyway where I can add output of one query as the input to the another query in the one query.

Also note that I need to go from table1 to table2 for some other details.

For example:

query{
 table1{
   username,
   email
 }
 table2(where:{username:username, email:email}){
   username,
   email,
   visitedLocations,
   booksRead
 }
}

You should use table relationships or custom functions .

What you want to do is not very clear, but I think you should redesign your database schema:

  • user table with PK
  • visitedLocations with one to many relationship with user table
  • booksRead with one to many relationship with user table

So, querying could be:

query {
    user {
        username
        email
        visitedLocations {
            location
        }
        booksRead {
            book
        }
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM