Skip to content

Commit 4486f10

Browse files
Glavin001mickhansen
authored andcommitted
Close #229. Support for commentToDescription option in attributeFields (#260)
* Close #229. Support for commentToDescription option in attributeFields * Change contributors to graphql-sequelize community
1 parent 24369d5 commit 4486f10

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
"sequelize"
2828
],
2929
"author": "Mick Hansen <maker@mhansen.io>",
30+
"contributors": [
31+
{
32+
"name": "graphql-sequelize community",
33+
"url": "https://github.com/mickhansen/graphql-sequelize/graphs/contributors"
34+
}
35+
],
3036
"license": "MIT",
3137
"bugs": {
3238
"url": "https://github.com/mickhansen/graphql-sequelize/issues"

src/attributeFields.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ module.exports = function (Model, options = {}) {
3333
}
3434
}
3535

36+
if (options.commentToDescription) {
37+
if (typeof attribute.comment === 'string') {
38+
memo[key].description = attribute.comment;
39+
}
40+
}
41+
3642
return memo;
3743
}, {});
3844

test/unit/attributeFields.test.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ describe('attributeFields', function () {
6868
},
6969
dateonly:{
7070
type:Sequelize.DATEONLY
71+
},
72+
comment:{
73+
type: Sequelize.STRING,
74+
comment: 'This is a comment'
7175
}
72-
7376
}, {
7477
timestamps: false
7578
});
@@ -80,7 +83,7 @@ describe('attributeFields', function () {
8083

8184

8285
expect(Object.keys(fields)).to.deep.equal(['id', 'email', 'firstName', 'lastName', 'char', 'float', 'decimal', 'enum',
83-
'enumTwo', 'list', 'virtualInteger', 'virtualBoolean','date','time','dateonly']);
86+
'enumTwo', 'list', 'virtualInteger', 'virtualBoolean','date','time','dateonly','comment']);
8487

8588

8689
expect(fields.id.type).to.be.an.instanceOf(GraphQLNonNull);
@@ -121,7 +124,7 @@ describe('attributeFields', function () {
121124
expect(Object.keys(fields)).to.deep.equal([
122125
'mappedId', 'email', 'firstName', 'lastName', 'char', 'float', 'decimal',
123126
'enum', 'enumTwo', 'list', 'virtualInteger', 'virtualBoolean', 'date',
124-
'time', 'dateonly'
127+
'time', 'dateonly', 'comment'
125128
]);
126129
});
127130

@@ -132,13 +135,17 @@ describe('attributeFields', function () {
132135
expect(Object.keys(fields)).to.deep.equal([
133136
'ids', 'emails', 'firstNames', 'lastNames', 'chars', 'floats', 'decimals',
134137
'enums', 'enumTwos', 'lists', 'virtualIntegers', 'virtualBooleans',
135-
'dates', 'times', 'dateonlys'
138+
'dates', 'times', 'dateonlys', 'comments'
136139
]);
137140
});
138141

139142
it('should be possible to exclude fields', function () {
140143
var fields = attributeFields(Model, {
141-
exclude: ['id', 'email', 'char', 'float', 'decimal', 'enum', 'enumTwo', 'list', 'virtualInteger', 'virtualBoolean','date','time','dateonly']
144+
exclude: [
145+
'id', 'email', 'char', 'float', 'decimal', 'enum',
146+
'enumTwo', 'list', 'virtualInteger', 'virtualBoolean',
147+
'date','time','dateonly','comment'
148+
]
142149
});
143150

144151
expect(Object.keys(fields)).to.deep.equal(['firstName', 'lastName']);
@@ -248,5 +255,14 @@ describe('attributeFields', function () {
248255
expect(fields.email.type).to.not.be.an.instanceOf(GraphQLNonNull);
249256
expect(fields.email.type).to.equal(GraphQLString);
250257
});
258+
259+
it('should be possible to comment attributes', function () {
260+
var fields = attributeFields(Model, {
261+
commentToDescription: true
262+
});
263+
264+
expect(fields.comment.description).to.equal('This is a comment');
265+
});
266+
251267
});
252268
});

0 commit comments

Comments
 (0)