hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.16k stars 2.76k forks source link

Declare graphql scalar for custom postgres domain #7999

Open brunolca opened 2 years ago

brunolca commented 2 years ago

Is your proposal related to a problem?

I am using a jsonb field for storing custom information. I am using a postgres domain to check the shape of the object. I would like to be able to add client side typing for this field. To do this I could use custom scalar but this field is typed as jsonb scalar in the resulting graphql schema.


Describe the solution you'd like

In the same fashion Hasura is creating custom scalar for each custom type in postgres (eg: citext extension or creating a composite type), a custom scalar could be created for each custom domain.

For now, custom domain are listed when creating a table using the console but the underlying type is displayed after creating the table.


Example

When creating a user table with a custom address jsonb row, the resulting workflow would be:

  1. Create a domain called address based on jsonb
  2. Create a table user with an address row using the address domain
  3. The resulting graphql object type would use the custom scalar called address
  4. Use graphql codegen to generate types for the resulting schema and map address to the corresponding typescript type

This isn't strict typing typescript type and posgres domain may be out of sync...

ferm10n commented 2 years ago

Hi, can you try this approach for overriding schema types provided by hasura? I know it works for json, and I believe it should work for domains based on json types.