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.13k stars 2.76k forks source link

Custom functions expect wrong argument type for Domains #6062

Open PedroBern opened 3 years ago

PedroBern commented 3 years ago

Summary

When using domains as argument type for a custom function, hasura always expect a string, even for number domains.

Steps to reproduce

Create a domain:

CREATE DOMAIN seed_float AS FLOAT
  CHECK (value <= 1)
  CHECK (value >= - 1);

Then, use it as the argument for a custom function:

CREATE OR REPLACE FUNCTION public.list_authors_random (seed seed_float DEFAULT 0 ::seed_float)
  RETURNS SETOF public.authors
  AS $$
  SELECT SETSEED(seed);
  SELECT * FROM public.authors ORDER BY random();
$$
LANGUAGE sql
STABLE;

Now do the following queries:

# working, but expected not to work
query ExpectNotToWork0 {
  list_authors_random(args: {seed: "0"}) {
    name
  }
}

# the validation works too
# error message:
# "Check constraint violation. value for domain seed_float violates check constraint \"seed_float_check\""
query ExpectNotToWork1 {
  list_authors_random(args: {seed: "2"}) {
    name
  }
}

# not working, but expected to work
# error message: "A string is expected for type: seed_float"
query ExpectToWork {
  list_authors_random(args: {seed: 0}) {
    name
  }
}

Concerns

Currently, I need to pass a string as input where the expected type should be a float. If in the future this is fixed, will it be backward compatible? I mean, support both string and the actual type?

tirumaraiselvan commented 3 years ago

Just adding a note that domains work as expected inside tables.