Skip to content

Commit 6813e81

Browse files
authored
fix: handle ignore for nested pointers (#3191)
* fix: handle ignore for nested pointers * add test
1 parent 0eaab36 commit 6813e81

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

packages/load/src/utils/pointers.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@ export function normalizePointers(
55
unnormalizedPointerOrPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[]
66
) {
77
const ignore: string[] = [];
8-
const pointerOptionMap = asArray(unnormalizedPointerOrPointers).reduce<{ [key: string]: any }>(
9-
(normalizedPointers, unnormalizedPointer) => {
10-
if (typeof unnormalizedPointer === 'string') {
11-
if (unnormalizedPointer.startsWith('!')) {
12-
ignore.push(unnormalizedPointer.replace('!', ''));
13-
} else {
14-
normalizedPointers[unnormalizedPointer] = {};
15-
}
16-
} else if (typeof unnormalizedPointer === 'object') {
17-
Object.assign(normalizedPointers, unnormalizedPointer);
18-
} else {
19-
throw new Error(`Invalid pointer ${unnormalizedPointer}`);
20-
}
8+
const pointerOptionMap: Record<string, Record<string, any>> = {};
9+
10+
const handlePointer = (rawPointer: string, options = {}) => {
11+
if (rawPointer.startsWith('!')) {
12+
ignore.push(rawPointer.replace('!', ''));
13+
} else {
14+
pointerOptionMap[rawPointer] = options;
15+
}
16+
};
2117

22-
return normalizedPointers;
23-
},
24-
{}
25-
);
18+
for (const rawPointer of asArray(unnormalizedPointerOrPointers)) {
19+
if (typeof rawPointer === 'string') {
20+
handlePointer(rawPointer);
21+
} else if (typeof rawPointer === 'object') {
22+
for (const [path, options] of Object.entries(rawPointer)) {
23+
handlePointer(path, options);
24+
}
25+
} else {
26+
throw new Error(`Invalid pointer '${rawPointer}'.`);
27+
}
28+
}
2629
return { ignore, pointerOptionMap };
2730
}

packages/load/tests/loaders/schema/schema-from-typedefs.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,18 @@ describe('schema from typedefs', () => {
173173
});
174174
expect(result.getTypeMap()["User"]).toBeDefined()
175175
})
176+
177+
it('should be able to exclude documents via nested negative glob', async () => {
178+
await load([
179+
'./tests/loaders/schema/test-files/schema-dir/user.graphql',
180+
'./tests/loaders/schema/test-files/schema-dir/invalid.graphql',
181+
{
182+
'!./tests/loaders/schema/test-files/schema-dir/i*.graphql' : {}
183+
}
184+
], {
185+
loaders: [new GraphQLFileLoader()],
186+
includeSources: true,
187+
});
188+
})
176189
})
177190
});

0 commit comments

Comments
 (0)