Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphql error: enum type does not exist because case sensitivity was not recognized #4014

Closed
gentleShark opened this issue Mar 3, 2020 · 12 comments
Assignees
Labels
a/api/graphql c/server Related to server ds-ten k/bug Something isn't working k/enhancement New feature or improve an existing feature

Comments

@gentleShark
Copy link

gentleShark commented Mar 3, 2020

I have an existing postgres DB with an enum (native Postgres enum type) named "enum_Motivations_desired_solution" on a table named "Motivations". When I try to insert into the table, Hasura throws an error indicating it is looking for an enum of the same name but in lower case. If I re-name the enum in Postgres to be lower case, it solves the problem.
The error:
{
"errors": [
{
"extensions": {
"path": "$.selectionSet.insert_Interactions.args.objects[0].Motivations.data",
"code": "constraint-error"
},
"message": "type "enum_motivations_desired_solution" does not exist"
}
]
}

The query:

mutation InteractionTest {
  insert_Interactions(objects: [
    {
      OwnerId: 5,
      forUserId: 1,
      initiatedByUserId: 1,
      Motivations: {
      data: [
        {
          desired_solution: "solution A",
          MotivatingFactors: {
            data: [{
              isCurrentFactor: true,
              commonFactor: "A"
            },
            {
              isCurrentFactor: true,
              commonFactor: "B"
            }]
          }
        }
      ]
    }
    }
  ]) {
    affected_rows
    returning {
      Motivations {
        desired_solution
        MotivatingFactors {
          commonFactor
          isCurrentFactor
        }
      }
    }
  }
}
@gentleShark gentleShark changed the title enum name not found by Hasura because its case sensitivity was not recognized Graphql error: enum type does not exist because case sensitivity was not recognized Mar 3, 2020
@marionschleifer marionschleifer added c/server Related to server k/bug Something isn't working labels Mar 6, 2020
@perrosnk
Copy link

Did you find any solution to this?

@gentleShark
Copy link
Author

@perrosnk No. I've just been manually renaming the enum to lower case in Postgres to get past the problem.

@abooij abooij self-assigned this May 7, 2020
@abooij
Copy link
Contributor

abooij commented May 8, 2020

I am trying to reproduce this issue, so that I can create a minimum working example of this, and figure out what is happening here. Could you please tell me some details?

  1. Which version of GraphQL Engine and PostgreSQL are you running?
  2. Can you describe your Postgres tables? What columns do your tables have, and what foreign keys have you set up?
  3. Which relations have you configured in GraphQL engine?

@lohazo
Copy link

lohazo commented Aug 23, 2020

I have same issue with enum
image
image

@ravikiran438
Copy link

Refer to enums in the hasura graphql engine section of the documentation. You may have to copy native PG enum types to referenced tables approach. After that alter existing column to TEXT data type and add foreign key to the new referenced table.

@dariusj18
Copy link

This should be as simple as ensuring that the enum type name is wrapped in double quotes.

@docforcedev
Copy link

@ravikiran438 This is a bug. If the enum name contains an uppercase letter, it will be flattened to lowercase and then this error will appear. We had EnumName and changed it to enumname and it worked. Hasura does not properly handle case sensitivity on enum fields.

@sassela
Copy link
Contributor

sassela commented Mar 30, 2022

hey folks, thanks for your patience. We'll be triaging this bug shortly. I believe I'm able to reproduce with the following setup on v2.3.1. Please take a look and let me know if this seems like a reasonable minimal repro, or if I've missed anything compared to the original bug report?

DDL statements on a Postgres DB, using example from Hasura docs

CREATE TABLE MixedCase (
  value text PRIMARY KEY,
  comment text
);

INSERT INTO MixedCase (value, comment) VALUES
  ('user', 'Ordinary users'),
  ('moderator', 'Users with the privilege to ban users'),
  ('administrator', 'Users with the privilege to set users’ roles');

GraphQL query via Hasura console

{
  MixedCase {
    comment
    value
  }
}

Expected response

{
  "data": {
    "MixedCase": [
      {
        "comment": "Ordinary users",
        "value": "user"
      },
      {
        "comment": "Users with the privilege to ban users",
        "value": "moderator"
      },
      {
        "comment": "Users with the privilege to set users’ roles",
        "value": "administrator"
      }
    ]
  }
}

Actual response

{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.MixedCase",
        "code": "validation-failed"
      },
      "message": "field \"MixedCase\" not found in type: 'query_root'"
    }
  ]
}

cc @gentleShark @lohazo @docforcedev @dariusj18 @perrosnk

@sassela sassela assigned sassela and unassigned abooij and 0x777 Mar 30, 2022
@dariusj18
Copy link

When executing your queries you will want to use double quotes (and you might as well add a mixed case column while you are at it)

Also be sure to add an Enum type, since that is where the bug is. (Deleted prior comment and amended it for this)

ex.

CREATE TYPE "MixedCaseType" AS ENUM ('ONE', 'TWO');

CREATE TABLE "MixedCase" (
  value text PRIMARY KEY,
  "comment" text,
  "mixedCaseType" "MixedCaseType"
);

INSERT INTO "MixedCase" (value, "comment", "mixedCaseType") VALUES
  ('user', 'Ordinary users', 'ONE'),
  ('moderator', 'Users with the privilege to ban users', 'ONE'),
  ('administrator', 'Users with the privilege to set users’ roles', 'TWO');

@sassela
Copy link
Contributor

sassela commented Mar 30, 2022

This is great, thanks for clarifying @gentleShark !

@rakeshkky
Copy link
Member

Additional context: We don't generate GraphQL enum types out of Postgres enums instead we generate simple custom scalar type. We treat them as Unknown type and insert data with String literals ('').

@ghost ghost added the k/enhancement New feature or improve an existing feature label Mar 31, 2022
@sassela sassela removed their assignment Apr 1, 2022
@rakeshkky rakeshkky self-assigned this Apr 6, 2022
@rakeshkky
Copy link
Member

Hi @gentleShark , thank you for the detailed bug report, and for your patience whilst we fix it. I'm happy to say this has been fixed at d561024, and will be available in the next stable release within two weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a/api/graphql c/server Related to server ds-ten k/bug Something isn't working k/enhancement New feature or improve an existing feature
Projects
None yet
Development

No branches or pull requests