Graphql-engine: After adding computed columns, GraphQL schema returns empty

Created on 24 Oct 2019  路  12Comments  路  Source: hasura/graphql-engine

This could easily be me not knowing how to create the computed column, or trying to create it in a way that is not supported.
But after I created it the GraphQL schema is blank.

Here are the steps to reproduce it.

CREATE TABLE public.calistings
(
    id uuid NOT NULL DEFAULT gen_random_uuid(),    
    location geometry(Point,4326)
)
CREATE FUNCTION calc_calisting_distance(calisting_row calistings,location json)
 RETURNS INTEGER AS $$
   SELECT ST_DISTANCE(calisting_row.location::geography, ST_GeomFromGeoJSON(location::text)::geography)::integer
 $$ LANGUAGE sql STABLE;
{
    "type":"add_computed_field",
    "args":{
        "table":{
            "name":"calistings",
            "schema":"public"
        },
        "name":"distance",
        "definition":{
            "function":{
                "name":"calc_calisting_distance",
                "schema":"public"
            },
            "table_argument":"calisting_row"
        }
    }
}

After I create the computed column, using the query endpoint. The GraphQL schema, from the intropsection query, is returned blank. If I remove the computed column, the introspection query returns the schema.

Tried checking the logs in the graphql-engine but no error is shown. I can see the introspection query hitting the server and responding with a 200 status OK.

I think the issue might be in the way I am creating the computed column. I didn't see a way to pass the function arguments to the api. Only the row name and type.

Thanks

server quickfix bug

Most helpful comment

thanks @leoalves

I actually found that the issue are not the computed fields themselves. The problem is with the functions. If you untrack the functions, then the schema shows up again and you can still query the computed fields

All 12 comments

Hi @leoalves, thanks for reporting. I'm able to reproduce this issue. Please find the fix in next release.

@rakeshkky I'm also having this same issue. When do you think you are releasing the next release?

Is there going to be a way to add a computed fields from the web console, without having to do it through the API ?

@tafelito the console support for computed fields will be added soon. Its being tracked at #3203

@rikinsk the introspection query is now failing with apollo tools in vscode and also graphql-codegen because of this. Is there any way to fix this before the next release? Do you have an ETA for the next release?
Sorry to be persistent with the ETA but this is preventing me to keep working right now
Thanks

@tafelito the next release should happen sometime next week. We don't have a fixed date though. The fix for this bug is ready in #3211 FYI.

In the meanwhile you can get your Hasura instance to work again by removing the added computed field. Luckily we have another bug currently where computed fields are not exported in the metadata and we can leverage that to solve your issue. You can just export metadata, reset metadata and import metadata back and things should work again I believe as the computed field will have been dropped.

edit: a safer way would be to drop the computed field via the metadata API

I actually being using the the metadata API to add and remove computed fields since I didn't see any other option to do that.

I tried removing the computed fields using the API but since I have a few computed fields right now, I'm not sure I removed all of them. Is there any way to get all computed fields?

edit: I think I removed all of them but the schema is still blank and I get the same error in graphql-codegen

@tafelito
I don't know if there is an api for that. But this query should give you all computed fields.

select * from hdb_catalog.hdb_computed_field;

thanks @leoalves

I actually found that the issue are not the computed fields themselves. The problem is with the functions. If you untrack the functions, then the schema shows up again and you can still query the computed fields

I support tafelito鈥檚 answer, the problem still exists in version v1.1.0-beta.2
And because of this, exporting the scheme to SDL does not work.

Error: Introspection must provide input type for arguments.

@OLDIN Please give us a minimal example to reproduce the error.

Edit: I'm able to get the corner case here. See https://github.com/hasura/graphql-engine/issues/3757

Hi there,

I ran into what I think is the exact same issue although in a different context -- custom function on a view. Happily, untracking the function as suggested got rid of the problem!

I actually found that the issue are not the computed fields themselves. The problem is with the functions. If you untrack the functions, then the schema shows up again and you can still query the computed fields

I was in the middle of making a reproduction... https://no-schema-but-custom-function.herokuapp.com/console/data/schema/public

You can see that if you toggle tracking and untracking the function, roles_for_user, the schema disappears and reappears.

Here is the up migration if it helps.

- type: run_sql
  args:
    sql: |
      CREATE OR REPLACE FUNCTION roles_for_user(user_row "user")
      RETURNS SETOF user_role AS $$
      SELECT
        ur.value
      FROM user_role ur
      RIGHT JOIN user_user_role_p uurp on uurp.user_role = ur.value
      RIGHT JOIN user_p up on uurp.user_p_id = user_row.p_id
      $$ LANGUAGE sql STABLE;
- type: track_function
  args:
    schema: public
    name: roles_for_user
- type: add_computed_field
  args:
    table:
      name: user
      schema: public
    name: roles_for_user
    definition:
      function:
        name: roles_for_user
        schema: public
      table_argument: user_row
Was this page helpful?
0 / 5 - 0 ratings

Related issues

coco98 picture coco98  路  3Comments

egislook picture egislook  路  3Comments

jjangga0214 picture jjangga0214  路  3Comments

bogdansoare picture bogdansoare  路  3Comments

marionschleifer picture marionschleifer  路  3Comments