Skip to content

Commit d78f09e

Browse files
committed
Use exclude when calling loadDocuments
1 parent fbb4726 commit d78f09e

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

src/project-config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,21 @@ export class GraphQLProjectConfig {
161161
return [];
162162
}
163163

164-
return this._extensionsRegistry.loaders.documents.loadDocuments(pointer, options);
164+
return this._extensionsRegistry.loaders.documents.loadDocuments(pointer, {
165+
...options,
166+
ignore: options?.ignore ? options?.ignore : this.exclude,
167+
});
165168
}
166169

167170
loadDocumentsSync(pointer: Pointer, options?: LoadTypedefsOptions): Source[] {
168171
if (!pointer) {
169172
return [];
170173
}
171174

172-
return this._extensionsRegistry.loaders.documents.loadDocumentsSync(pointer, options);
175+
return this._extensionsRegistry.loaders.documents.loadDocumentsSync(pointer, {
176+
...options,
177+
ignore: options?.ignore ? options?.ignore : this.exclude,
178+
});
173179
}
174180

175181
// Rest

test/config.spec.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { buildSchema, buildASTSchema } from 'graphql';
22
import path from 'path';
3+
import { vi } from 'vitest';
34
import { TempDir } from './utils/temp-dir';
45
import { runTests } from './utils/runner';
56
import { loadConfig, loadConfigSync, ConfigNotFoundError, GraphQLConfig } from 'graphql-config';
@@ -275,6 +276,67 @@ runTests({ async: loadConfig, sync: loadConfigSync })((load, mode) => {
275276
expect(config.getProjectForFile('./foo/ignored/component.ts').name).toBe('bar');
276277
});
277278

279+
test.each(['loadDocumentsSync', 'loadDocuments'] as const)('%s uses exclude', async (method) => {
280+
temp.createFile(
281+
'.graphqlrc',
282+
`
283+
projects:
284+
foo:
285+
schema: ./foo.graphql
286+
include: ./foo/*.ts
287+
exclude: ./foo/ignored/**
288+
`,
289+
);
290+
291+
const config = await load({ rootDir: temp.dir });
292+
293+
const project = config.getProject('foo');
294+
295+
const loadDocumentsSyncSpy = vi
296+
.spyOn(project['_extensionsRegistry'].loaders.documents, method)
297+
.mockReturnValue([]);
298+
299+
await project[method]('./**/*');
300+
301+
expect(loadDocumentsSyncSpy).toHaveBeenCalledWith('./**/*', {
302+
ignore: './foo/ignored/**',
303+
});
304+
305+
loadDocumentsSyncSpy.mockRestore();
306+
});
307+
308+
test.each(['loadDocumentsSync', 'loadDocuments'] as const)(
309+
'%s respects options.ignore when provided (overrides exclude)',
310+
async (method) => {
311+
temp.createFile(
312+
'.graphqlrc',
313+
`
314+
schema: ./schema.graphql
315+
documents: ./**/*.graphql
316+
exclude:
317+
- "**/excluded/**"
318+
`,
319+
);
320+
321+
const config = await load({ rootDir: temp.dir });
322+
const project = config.getDefault();
323+
324+
const loadDocumentsSyncSpy = vi
325+
.spyOn(project['_extensionsRegistry'].loaders.documents, method)
326+
.mockReturnValue([]);
327+
328+
// Call with custom ignore - should override exclude
329+
await project[method]('./**/*.graphql', { ignore: '**/custom-ignored/**' });
330+
331+
// Verify it was called with custom ignore (NOT the exclude from config)
332+
expect(loadDocumentsSyncSpy).toHaveBeenCalledWith('./**/*.graphql', {
333+
ignore: '**/custom-ignored/**',
334+
});
335+
336+
loadDocumentsSyncSpy.mockRestore();
337+
},
338+
);
339+
278340
test('customizable config name', async () => {
279341
temp.createFile(schemaFilename, testSDL);
280342
temp.createFile('foo.config.js', `module.exports = { schema: '${schemaFilename}' }`);

0 commit comments

Comments
 (0)