Skip to content

Commit ffa7ed7

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

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-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: 65 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,70 @@ 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('schema.graphql', testSDL);
312+
313+
temp.createFile(
314+
'.graphqlrc',
315+
`
316+
schema: ./schema.graphql
317+
documents: ./**/*.graphql
318+
exclude:
319+
- "**/excluded/**"
320+
`,
321+
);
322+
323+
const config = await load({ rootDir: temp.dir });
324+
const project = config.getDefault();
325+
326+
// Create a spy on the internal method and mock its return value
327+
const loadDocumentsSyncSpy = vi
328+
.spyOn(project['_extensionsRegistry'].loaders.documents, method)
329+
.mockReturnValue([]);
330+
331+
// Call with custom ignore - should override exclude
332+
await project[method]('./**/*.graphql', { ignore: '**/custom-ignored/**' });
333+
334+
// Verify it was called with custom ignore (NOT the exclude from config)
335+
expect(loadDocumentsSyncSpy).toHaveBeenCalledWith('./**/*.graphql', {
336+
ignore: '**/custom-ignored/**',
337+
});
338+
339+
loadDocumentsSyncSpy.mockRestore();
340+
},
341+
);
342+
278343
test('customizable config name', async () => {
279344
temp.createFile(schemaFilename, testSDL);
280345
temp.createFile('foo.config.js', `module.exports = { schema: '${schemaFilename}' }`);

0 commit comments

Comments
 (0)