Custom function mutations is expecting return type as a required argument
Discussed in https://github.com/hasura/graphql-engine/discussions/8954
Originally posted by securisec September 11, 2022
TLDR : The mutation is expecting the return type as a valid arg. Based on the example, it is expecting after_updated as a valid args which may be a bug.
When working with a custom function, I am having an issue that seems to defy the docs. I have a custom function that gets the user id from x-hasura-user-id and updates a table.
My custom function signature is:
CREATE OR REPLACE FUNCTION db.make_an_update(hasura_session json)
RETURNS TABLE(after_updated db.some_table)
LANGUAGE sql VOLATILE
AS $function$
...
WHERE
user_id = ((hasura_session ->> 'x-hasura-user-id')::text)
RETURNING
*;
$function$
This function is tracked, and tested outside of hasura to make sure it works. The tracking metadata is specified as such:
function:
name: make_an_update
schema: db
configuration:
custom_root_fields: {}
session_argument: hasura_session
The issue I am having is that when making a mutation query, i am getting the error missing required field 'args', but when trying to specify empty args, like make_an_update(args:{}), I am getting the error Non default arguments cannot be omitted.
Based on the docs, I have the hasura_session specified in the metadata, and the function is working as expected and tracked, I have tried creating as VOLATILE and not, but cannot get past this args required error.
I tried working with both hasura versions 2.11.1 and 2.12.0-ce
After doing some debugging, it looks like when calling the mutation, it is expecting after_updated as a valid args which seems like a bug because it is not a function argument.
When trying to delete this function, the error is interesting because it to shows the function requires two arguments. (the function will fail to delete.
"statement": "DROP FUNCTION \"db\".\"update_something\"(\"pg_catalog\".\"json\", \"db\".\"some_table\");"