Create relationship to user

Now that the view has been created, we need a way to be able to fetch user information based on the id column of the view. Let's create a manual relationship from the view online_users to the table users using the id column of the view.

Head to Console -> Data -> online_users -> Relationships page.

Add a new relationship manually by choosing the relationship type to be Object Relationship. Enter the relationship name as user. Select the configuration for the current column as id and the remote table would be users and the remote column would be id again.

We are mapping the current view's id column to users table's id column to create the relationship.

create relationship from view

Let's explore the GraphQL APIs for the relationship created.

query {
online_users {
id
last_seen
user {
id
name
}
}
}

Great! We are completely done with data modeling for the app.

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin
graphql-handbook