mickhansen / graphql-sequelize

GraphQL & Relay for MySQL & Postgres via Sequelize
MIT License
1.9k stars 172 forks source link

Enum Types cause duplicate type #684

Closed coolhand79 closed 4 years ago

coolhand79 commented 4 years ago

When using attributeFields on a model with an enum type, I consistently get

"Error: Schema must contain uniquely named types but contains multiple types named "ComplianceNotenoteTypeEnumType"."

I see references to using cache as a config, but it seems to have no affect.

var cache = {};
module.exports = new GraphQLObjectType({
  name: ComplianceNote.name,
  description: 'A ComplianceNote',
  fields: () => ({
    ...attributeFields(ComplianceNote, {
      cache,
    }),
  }),
});

FWIW, my model looks like this:

module.exports = (sequelize, DataTypes) => {
  const ComplianceNote = sequelize.define(
    'ComplianceNote',
    {
      notes: DataTypes.TEXT,
      noteType: {
        type: DataTypes.ENUM,
        values: [
          'Live Support',
          'Mailed Letter',
          'Need Demographics',
        ],
      },
    },
    { ...require('./utils/modelCommons') }
  );
  ComplianceNote.associate = function associate(models) {

  };
  return ComplianceNote;
};
mickhansen commented 4 years ago

You must be calling attributeFields multiple places, are you using the same cache object each place you do that?

mickhansen commented 4 years ago

https://github.com/mickhansen/graphql-sequelize/blob/master/src/attributeFields.js#L39

coolhand79 commented 4 years ago

You are absolutely right. I had to place a breakpoint to find it. Once I did, adding the cache object solved it. Thanks!