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

Issue adding Enum field into a remote_schema #3540

Open
leoalves opened this issue Dec 15, 2019 · 5 comments
Open

Issue adding Enum field into a remote_schema #3540

leoalves opened this issue Dec 15, 2019 · 5 comments
Assignees
Labels
c/remote-schemas Issues related to Remote Schemas k/bug Something isn't working p/high candidate for being included in the upcoming sprint

Comments

@leoalves
Copy link

I followed the tutorial to Add an Enum field from the docs. But when trying to add a Remote Schema with the enum in the type definition Hasura returns the following error:
Adding remote schema failed types: [ user_role_enum ] have mismatch with current graphql schema. HINT: Types must be same.

The type definitions are the same in both places

Steps to reproduce it:

CREATE TABLE users (
  id serial PRIMARY KEY,
  name text NOT NULL,
  role text NOT NULL
);
CREATE TABLE user_role (
  value text PRIMARY KEY,
  comment text
);
INSERT INTO user_role (value, comment) VALUES
  ('user', 'Ordinary users'),
  ('moderator', 'Users with the privilege to ban users'),
  ('administrator', 'Users with the privilege to set users’ roles');

Set the table as enum in the console

ALTER TABLE users ADD CONSTRAINT
  users_role_fkey FOREIGN KEY (role) REFERENCES user_role;

Added a Remote Schema with the following types definition:

input users_insert_input {
    id: Int
    name: String
    role: user_role_enum
  }

  type users {
    id: Int!
    name: String!
    role: user_role_enum!
  }

  enum user_role_enum {
    # Users with the privilege to set users’ roles
    administrator
    # Users with the privilege to ban users
    moderator
    # Ordinary users
    user
  }

  type Query {
    hello: Boolean
  }

  type Mutation {
    create_remote_user(data: users_insert_input!): users
  }
@leoalves
Copy link
Author

leoalves commented Dec 15, 2019

I tried with the type definition just like in the docs page and it worked:

enum user_role_enum {
    "Users with the privilege to set users’ roles"
    administrator

    "Users with the privilege to ban users"
    moderator

    "Ordinary users"
    user
  }

What is confusing in this case is that the type definition returned from the introspection query is the same as my first comment.

enum user_role_enum {
    # Users with the privilege to set users’ roles
    administrator
    # Users with the privilege to ban users
    moderator
    # Ordinary users
    user
  }

Always when creating a remote schema I use the returned type from the instrospection query, to make sure both types are the same. And that is why I got this error. If there is a way for it to be the same. Or if Hasura could strip out the comments when comparing enum types that would be good.

Thanks

@marionschleifer marionschleifer added the c/remote-schemas Issues related to Remote Schemas label Dec 17, 2019
@tirumaraiselvan
Copy link
Contributor

@lexi-lambda @rakeshkky Any thoughts why equating types

enum user_role_enum {
    "Users with the privilege to set users’ roles"
    administrator

    "Users with the privilege to ban users"
    moderator

    "Ordinary users"
    user
  }

with

enum user_role_enum {
    # Users with the privilege to set users’ roles
    administrator
    # Users with the privilege to ban users
    moderator
    # Ordinary users
    user
  }

would fail?

Either way, should we remove including Descriptions for type equalities?

@litchfield
Copy link

I've encountered this error too, it completely prevents me from using schema stitching. It seems all Hasura needs to do is strip comments when comparing schemas. Maybe a quick fix?

Hasura schema excerpt --

...
# select columns of table "my_table"
enum my_table_select_column {

  # column name
  id

  # column name
  name

}

My remote schema --

...
enum my_table_select_column {
  id
  name
}

Hasura error --

types: [ my_table_select_column ] have mismatch with current graphql schema. HINT: Types must be same.

@tirumaraiselvan tirumaraiselvan added support/needs-triage Needs to be triaged so that we have enough information to add this to our backlog support/needs-action support ticket that requires action by team and removed support/needs-triage Needs to be triaged so that we have enough information to add this to our backlog labels Mar 11, 2020
@Miyou
Copy link

Miyou commented Apr 7, 2020

I'm having the same problem, but in my case I have no comments in my schema. The two enum definitions are exactly the same. Help with fixing this would be greatly appreciated! Right now my only solution seems to be to not use an enum.

@coco98 coco98 added k/bug Something isn't working p/high candidate for being included in the upcoming sprint and removed support/needs-action support ticket that requires action by team labels Oct 7, 2021
@deathemperor
Copy link
Contributor

@tirumaraiselvan any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/remote-schemas Issues related to Remote Schemas k/bug Something isn't working p/high candidate for being included in the upcoming sprint
Projects
None yet
Development

No branches or pull requests

7 participants