question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: Hasura v1.4alpha volatile functions not showing in the GraphQL Schema

See original GitHub issue

When tracking a volatile function, the function is not showing in the GraphQL schema.

Hasura version: v1.4.0-alpha.1, deployed to Heroku. https://bug-volatile-function-hasura.herokuapp.com/console

Steps to reproduce:

  1. create table
CREATE TABLE article
(
    id    serial primary key,
    title        TEXT not null,
    content      TEXT not null
);
  1. create function
CREATE OR REPLACE FUNCTION public.add_article(title text, content text)
 RETURNS SETOF article
 LANGUAGE plpgsql
AS $function$
DECLARE inserted_article_id integer;
BEGIN
  IF LENGTH(content) < 10 THEN
    INSERT into article (title, content) values (title, content) RETURNING id INTO inserted_article_id;
  ELSE
    RAISE EXCEPTION 'article is too large';
  END IF;
  RETURN QUERY SELECT * from article where id = inserted_article_id;
END;
$function$
  1. In the data tab track the table
  2. In the data tab track the function as a mutation

add_article does not show in the GraphQL schema.

I tried with and without the x-hasura-admin-secret in the server flags Different functions Adding permission to the role user and trying the role applied as user.

I wasn’t able to make it work at all.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jaekookcommented, Jan 19, 2022

2.1.1 We also had same problem. Admin is accessable but other role can not see the function at mutation. We added HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS=false to config and allow permission to our role.

0reactions
BenoitRanquecommented, Apr 20, 2022

This is not a bug, per the documentation:

When the --infer-function-permissions flag is set to false, a function f, stable, immutable or volatile is only exposed for a role r if there is a permission defined on the function f for the role r, creating a function permission will only be allowed if there is a select permission on the table type. When the --infer-function-permissions flag is set to true or the flag is omitted (defaults to true), the permission of the function is inferred from the select permissions from the target table of the function, only for stable/immutable functions. Volatile functions are not exposed to any of the roles in this case.

Therefore, unless the HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS env var is set to false, we expect volatile functions to be exposed as mutations and only available to the admin role.

However it seems the actual behavior when an existing function is tracked (as opposed to tracking the function during creation) is slightly different, and the resulting metadata does allow users to set permissions for the function. This may be a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Hasura GraphQL engine errors
This section provides references that can help in troubleshooting errors when developing with Hasura. Logs​. In order to find out about the origins...
Read more >
GraphQL Engine server config reference - Hasura
For the graphql-engine command these are the available flags and environment ... Volatile functions are not exposed to any of the roles in...
Read more >
Top GraphQL Errors and How to fix them
Technically this error came out of using a field which doesn't exist (either due to Auth or schema not really having the field)....
Read more >
Metadata API Reference: Custom Functions - Hasura
pg_track_function is used to add a custom SQL function to the GraphQL schema. It supports more configuration options than v1, and also supports...
Read more >
Postgres: Extend schema with SQL functions - Hasura
Hasura GraphQL engine lets you expose certain types of custom functions as top level fields in the GraphQL API to allow querying them...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found