Skip to content

Commit bddfaff

Browse files
committed
Merge pull request #37 from idris/enums-with-dashes
GraphQL enums support underscores
2 parents ed8db2a + d7ca9a7 commit bddfaff

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/typeMapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function toGraphQL(sequelizeType, sequelizeTypes) {
3232
} = sequelizeTypes;
3333

3434
// Regex for finding special characters
35-
const specialChars = /[^a-z\d]/i;
35+
const specialChars = /[^a-z\d_]/i;
3636

3737
if (sequelizeType instanceof BOOLEAN) return GraphQLBoolean;
3838
if (sequelizeType instanceof FLOAT) return GraphQLFloat;

test/attributeFields.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('attributeFields', function () {
3939
type: Sequelize.ENUM('first', 'second')
4040
},
4141
enumTwo: {
42-
type: Sequelize.ENUM('foo', 'foo-bar')
42+
type: Sequelize.ENUM('foo_bar', 'foo-bar')
4343
},
4444
list: {
4545
type: Sequelize.ARRAY(Sequelize.STRING)
@@ -108,4 +108,12 @@ describe('attributeFields', function () {
108108
expect(fields.enumTwo.type.getValues()[1].name).to.equal('fooBar');
109109
expect(fields.enumTwo.type.getValues()[1].value).to.equal('foo-bar');
110110
});
111+
112+
it('should support enum values with underscores', function () {
113+
var fields = attributeFields(Model);
114+
115+
expect(fields.enumTwo.type.getValues()).to.not.be.undefined;
116+
expect(fields.enumTwo.type.getValues()[0].name).to.equal('foo_bar');
117+
expect(fields.enumTwo.type.getValues()[0].value).to.equal('foo_bar');
118+
});
111119
});

0 commit comments

Comments
 (0)