Skip to content

Custom functions expect wrong argument type for Domains #6062

Open
@PedroBern

Description

@PedroBern

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?

Metadata

Metadata

Assignees

Labels

a/apik/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions