Skip to content

Commit 39bf4a4

Browse files
committed
Allow nested objects with similar keys.
Fixes #206
1 parent 7ecc82e commit 39bf4a4

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/validation/__tests__/UniqueInputFieldNames.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ describe('Validate: Unique input field names', () => {
4848
`);
4949
});
5050

51+
it('allows for nested input objects with similar fields', () => {
52+
expectPassesRule(UniqueInputFieldNames, `
53+
{
54+
field(arg: {
55+
deep: {
56+
deep: {
57+
id: 1
58+
}
59+
id: 1
60+
}
61+
id: 1
62+
})
63+
}
64+
`);
65+
});
66+
5167
it('duplicate input object fields', () => {
5268
expectFailsRule(UniqueInputFieldNames, `
5369
{

src/validation/rules/UniqueInputFieldNames.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ export function duplicateInputFieldMessage(fieldName: any): string {
2222
* uniquely named.
2323
*/
2424
export function UniqueInputFieldNames(): any {
25-
var knownNames = Object.create(null);
25+
let knownNameStack = [];
26+
let knownNames = Object.create(null);
27+
2628
return {
27-
ObjectValue() {
28-
knownNames = Object.create(null);
29+
ObjectValue: {
30+
enter() {
31+
knownNameStack.push(knownNames);
32+
knownNames = Object.create(null);
33+
},
34+
leave() {
35+
knownNames = knownNameStack.pop();
36+
}
2937
},
3038
ObjectField(node) {
3139
var fieldName = node.name.value;

0 commit comments

Comments
 (0)