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

Schema validation error when using enum in two tables #35

Closed
artem-barmin opened this issue May 3, 2016 · 1 comment
Closed

Schema validation error when using enum in two tables #35

artem-barmin opened this issue May 3, 2016 · 1 comment

Comments

@artem-barmin
Copy link
Contributor

I have following schema:

create type user_opinion as enum ('pro','cons');
create table user_view(id serial primary key,view user_opinion);
create table argument(id serial primary key,side user_opinion);

When I am trying to start postgraphql it gives me error:

Error: Schema must contain unique named types but contains multiple types named "UserOpinion".
    at invariant (/usr/lib/node_modules/postgraphql/node_modules/graphql/jsutils/invariant.js:19:11)
    at typeMapReducer (/usr/lib/node_modules/postgraphql/node_modules/graphql/type/schema.js:207:29)
    at /usr/lib/node_modules/postgraphql/node_modules/graphql/type/schema.js:234:22
    at Array.forEach (native)
    at /usr/lib/node_modules/postgraphql/node_modules/graphql/type/schema.js:225:37
    at typeMapReducer (/usr/lib/node_modules/postgraphql/node_modules/graphql/type/schema.js:236:7)
    at /usr/lib/node_modules/postgraphql/node_modules/graphql/type/schema.js:234:22
    at Array.forEach (native)
    at /usr/lib/node_modules/postgraphql/node_modules/graphql/type/schema.js:225:37
    at typeMapReducer (/usr/lib/node_modules/postgraphql/node_modules/graphql/type/schema.js:236:7)
    at Array.reduce (native)
    at new GraphQLSchema (/usr/lib/node_modules/postgraphql/node_modules/graphql/type/schema.js:104:34)
    at schema (/usr/lib/node_modules/postgraphql/dist/graphql/createSchema.js:25:39)
    at /usr/lib/node_modules/postgraphql/dist/createGraphqlSchema.js:32:57
    at next (native)
    at step (/usr/lib/node_modules/postgraphql/dist/createGraphqlSchema.js:17:191)

Schema validator works using reference comparison(===), so that can be fixed by using cache by name for enum types in https://github.com/calebmer/postgraphql/blob/master/src/graphql/getColumnType.js#L113.

artem-barmin pushed a commit to artem-barmin/postgraphql that referenced this issue May 3, 2016
calebmer pushed a commit that referenced this issue May 5, 2016
* fix(graphql): enum types get cached (#35)

* lint fixes

* added integration and unit test
@calebmer
Copy link
Collaborator

calebmer commented May 5, 2016

Fixed in 1.2.2 with #35, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants