Search code examples
postgresqlgraphqlpsqlhasuracomputed-field

GraphQL : OverLoaded function error when adding a computed field


I am trying to add a computed field to my graphql table "user" in schema "abc" using the hasura API but receiving the following error :

**Saving computed field failed**
in table "abc.user": in computed field "allaccounts": function "abc.get_accounts" 
is overloaded. Overloaded functions are not supported

The function is added correctly :

  CREATE OR REPLACE FUNCTION abc.get_accounts(id bigint)
    RETURNS VARCHAR immutable AS $$
DECLARE
    value VARCHAR;
BEGIN
    SELECT array_to_string(ARRAY_AGG( name ORDER BY name ASC )::varchar[], ',', '')
           into value
    FROM abc.account
             INNER JOIN abc.user_account ON (account.id=user_account.account_id)
    where user_account.user_id = id group by user_id;
    return value;
END;
$$ LANGUAGE plpgsql;

id field is present in user table.

I am able to select the function "get_accounts" from the dropdown but getting an error on adding computed field. Any guidance is appreciated. Thank you.


Solution

  • Adding STABLE worked for me :

    CREATE OR REPLACE FUNCTION abc.all_accounts(user_row abc.user)
      RETURNS VARCHAR AS $$
    DECLARE
      value VARCHAR;
    BEGIN
      SELECT array_to_string(ARRAY_AGG( name ORDER BY name ASC )::varchar[], ',', '')
          into value
                   FROM abc.account
                          INNER JOIN abc.user_account ON (account.id=user_account.account_id)
                       where abc.user_account.user_id = user_row.id
                   group by user_id;
      return value;
    END;
    $$ LANGUAGE plpgsql STABLE;