Skip to content

Commit f429a17

Browse files
committed
add support for attributeFields.only and document .exclude, closes #1, #26
1 parent cdf3fe2 commit f429a17

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ var Model = sequelize.define('User', {
140140

141141
import {attributeFields} from 'graphql-sequelize';
142142

143-
attributeFields(Model);
143+
attributeFields(Model, {
144+
// ... options
145+
exclude: [], // array of model attributes to ignore - default: []
146+
only: [], // only generate definitions for these model attributes - default: null
147+
});
144148

145149
/*
146150
{

src/attributeFields.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = function (Model, options) {
66

77
var result = Object.keys(Model.rawAttributes).reduce(function (memo, key) {
88
if (options.exclude && ~options.exclude.indexOf(key)) return memo;
9+
if (options.only && !~options.only.indexOf(key)) return memo;
910

1011
var attribute = Model.rawAttributes[key]
1112
, type = attribute.type;

test/attributeFields.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ describe('attributeFields', function () {
9191
expect(Object.keys(fields)).to.deep.equal(['firstName', 'lastName']);
9292
});
9393

94+
it('should be possible to specify specific fields', function () {
95+
var fields = attributeFields(Model, {
96+
only: ['id', 'email', 'list']
97+
});
98+
99+
expect(Object.keys(fields)).to.deep.equal(['id', 'email', 'list']);
100+
});
101+
94102
it('should automatically name enum types', function () {
95103
var fields = attributeFields(Model);
96104

0 commit comments

Comments
 (0)