graphql-engine: Hasura doesn't find custom type declared in a schema other than public

When declaring a custom type in hasura in a schema other than public and trying to use it on a column, it’s not being listed as column type, we can get past that by declaring the column using the SQL tool in data but then when trying to filter based on that column i keep getting a constraint-error

for example

let’s say i have the schema interview and i declare the following custom type

create type interview.status_type as enum('pending', 'disqualified');

and then i use the declared type in another sql statement creating a column

alter table interview.person_interviews add column status interview.status_type not null default 'pending'

and then say i were to run the following graphql query

{
  interview_person_interviews(where: {status: {_eq: "pending"}}) {
    id
  }
}

after running the above query i get the following error

{
  "errors": [
    {
      "extensions": {
        "path": "$",
        "code": "constraint-error"
      },
      "message": "type \"status_type\" does not exist"
    }
  ]
}

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 15
  • Comments: 17

Commits related to this issue

Most upvoted comments

This solution is working. Thanks !

I did not know search_path could be set globally.

Any news on this?

In Postgres you can run something like this to make this work: alter database DB_NAME set search_path = public, SCHEMA_ONE, SCHEMA_TWO, SCHEMA_ETC;

I’m affected by this as well (trying to do an update mutation on a table with a custom enum type in a non-default namespace, and it gives the “type xxx does not exist” because Hasura construct SQL that contains a non-qualified typename in the constructed SQL). There was a related bug #4014 that was just fixed in https://github.com/hasura/graphql-engine/commit/d5610242542eb10c8d3ba825f2bd34fb23fb4faf.

@rakeshkky @0x777 Maybe this commit lays the foundation for fixing this one? This is pretty severe as it completely blocks using Hasura with any PostgreSQL database that has a custom enum type in a non-default schema.

To fix, it seems like first PGScalarType, PGEnumScalar type would need to contain both a namespace and a typename: https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Backends/Postgres/SQL/Types.hs#L321

This would affect areas that construct a PGEnumScalar where it needs to add the namespace as well, such as: https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Backends/Postgres/SQL/Types.hs#L437

Then, when the PGEnumScalar is translated to SQL text, it would need to add the namespace and not just the typename: https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Backends/Postgres/SQL/Types.hs#L361 https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Backends/Postgres/SQL/Types.hs#L368

There is already a concept in the code for qualified type names, QualifiedPGType, so maybe it’s just a matter of constructing a fully qualified type name instead of just the PGEnumScalar in the right place. https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Backends/Postgres/SQL/Types.hs#L525

It might be as simple as adding another case taking a QualifiedPGType and constructing the proper PGEnumScalar with the schema name included: https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Backends/Postgres/SQL/Types.hs#L558

I’m not familiar at all with Hasura code. But it seems most of the infrastructure is there to fix this, hopefully it would be a quick fix for someone familiar with the code.

I managed to fix it by appending the schema to the HASURA_GRAPHQL_DATABASE_URL env variable

postgres://…/my_db?options=-c%20search_path%my_schema,public

the appropriate full format: postgres://user:pass@host:5432/dbname?options=-c%20search_path%3Dmy_schema%2Cpublic

I managed to fix it by appending the schema to the HASURA_GRAPHQL_DATABASE_URL env variable

postgres://…/my_db?options=-c%20search_path%my_schema,public