Skip to content

Commit 2f634ac

Browse files
authored
Merge pull request #17 from indigotech/bugfix/arg-islist-missing
Bugfix - Added missing @arg isList option
2 parents 2590778 + 8123eca commit 2f634ac

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/decorator.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,41 +116,58 @@ describe('Decorators', function () {
116116
class Obj { @D.Field() someFunction( @D.Arg({ name: 'input' }) input: any) { } }
117117
const actual = getFieldMetadata(Obj.prototype, 'someFunction').args[0];
118118
assert(actual.name === 'input');
119+
assert(typeof actual.isNonNull === 'undefined');
120+
assert(typeof actual.isList === 'undefined');
119121
});
120122

121123
it('sets description to ArgumentMetadata with @Description', function () {
122124
class Obj { @D.Field() someFunction( @D.Description('some input') @D.Arg({ name: 'input' }) input: any) { } }
123125
const actual = getFieldMetadata(Obj.prototype, 'someFunction').args[0];
124126
assert(actual.name === 'input');
125127
assert(actual.description === 'some input');
128+
assert(typeof actual.isNonNull === 'undefined');
129+
assert(typeof actual.isList === 'undefined');
126130
});
127131

128132
it('sets description to ArgumentMetadata with description option', function () {
129133
class Obj { @D.Field() someFunction( @D.Arg({ name: 'input', description: 'some input' }) input: any) { } }
130134
const actual = getFieldMetadata(Obj.prototype, 'someFunction').args[0];
131135
assert(actual.name === 'input');
132136
assert(actual.description === 'some input');
137+
assert(typeof actual.isNonNull === 'undefined');
138+
assert(typeof actual.isList === 'undefined');
133139
});
134140

135141
it('sets isNonNull to ArgumentMetadata with @NonNull', function () {
136142
class Obj { @D.Field() someFunction( @D.NonNull() @D.Arg({ name: 'input' }) input: any) { } }
137143
const actual = getFieldMetadata(Obj.prototype, 'someFunction').args[0];
138144
assert(actual.name === 'input');
139145
assert(actual.isNonNull === true);
146+
assert(typeof actual.isList === 'undefined');
140147
});
141148

142149
it('sets isNonNull to ArgumentMetadata with nonNull option', function () {
143150
class Obj { @D.Field() someFunction( @D.Arg({ name: 'input', nonNull: true }) input: any) { } }
144151
const actual = getFieldMetadata(Obj.prototype, 'someFunction').args[0];
145152
assert(actual.name === 'input');
146153
assert(actual.isNonNull === true);
154+
assert(typeof actual.isList === 'undefined');
147155
});
148156

149157
it('sets isNonNull to ArgumentMetadata with @List', function () {
150158
class Obj { @D.Field() someFunction( @D.List() @D.Arg({ name: 'input' }) input: any) { } }
151159
const actual = getFieldMetadata(Obj.prototype, 'someFunction').args[0];
152160
assert(actual.name === 'input');
161+
assert(typeof actual.isNonNull === 'undefined');
153162
assert(actual.isList === true);
154163
});
164+
165+
it('sets isNonNull to ArgumentMetadata with isList', function () {
166+
class Obj { @D.Field() someFunction( @D.Arg({ name: 'input', isList: true }) input: any) { } }
167+
const actual = getFieldMetadata(Obj.prototype, 'someFunction').args[0];
168+
assert(actual.name === 'input');
169+
assert(typeof actual.isNonNull === 'undefined');
170+
assert(actual.isList === true);
171+
});
155172
});
156173
});

src/decorator.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface ArgumentOption extends DefaultOption {
8181
name: string;
8282
type?: any;
8383
nonNull?: boolean;
84+
isList?: boolean;
8485
}
8586

8687
export interface SchemaOption extends DefaultOption {
@@ -499,6 +500,20 @@ export function Arg(option: ArgumentOption) {
499500
if (option.nonNull) {
500501
setNonNullMetadata(target, propertyKey, index);
501502
}
503+
504+
// isList
505+
if (option.isList) {
506+
if (index >= 0) {
507+
setArgumentMetadata(target, propertyKey, index, {
508+
isList: true,
509+
});
510+
} else {
511+
createOrSetFieldTypeMetadata(target, {
512+
name: propertyKey,
513+
isList: true,
514+
});
515+
}
516+
}
502517
}
503518
} as Function;
504519
}

0 commit comments

Comments
 (0)