2 years ago

#21096

test-img

Salem

How can I specify custom GraphQL types for a Postgres view in Hasura?

I have a view that I'm tracking in Hasura. I essentially query one table and left-join additional data from other tables onto it:

CREATE
OR REPLACE VIEW "public"."user_summary" AS
SELECT
  u.id AS user_id,
  u.display_name AS user_display_name,
  s.display_name AS subscription_display_name
FROM
  user u 
    LEFT JOIN subscription s ON (u.id = s.user_id)
        

However, the GraphQL schema that Hasura generates for this view looks like this:

type userSummary {
  user_id: Int
  user_display_name: String
  subscription_display_name: String
}

Specifically, all of the types are optional. It might make sense for subscription_display_name to be missing — I'm using a left join because not all users have subscriptions — but a user ID and display name are always present and don't show up as optional in the types Hasura generates for them.

Is it possible to provide better types to Hasura for this view? Or separately, is there something I'm missing that causes all of these properties to be marked as optional?

postgresql

graphql

hasura

0 Answers

Your Answer

Accepted video resources