From d78f09ef8ae4bef6dfde060cc880fd4b0c25d265 Mon Sep 17 00:00:00 2001 From: Matt Thomas Date: Tue, 21 Oct 2025 13:38:48 +0100 Subject: [PATCH] Use exclude when calling loadDocuments --- src/project-config.ts | 10 +++++-- test/config.spec.ts | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/project-config.ts b/src/project-config.ts index 660b62102..7428c3765 100644 --- a/src/project-config.ts +++ b/src/project-config.ts @@ -161,7 +161,10 @@ export class GraphQLProjectConfig { return []; } - return this._extensionsRegistry.loaders.documents.loadDocuments(pointer, options); + return this._extensionsRegistry.loaders.documents.loadDocuments(pointer, { + ...options, + ignore: options?.ignore ? options?.ignore : this.exclude, + }); } loadDocumentsSync(pointer: Pointer, options?: LoadTypedefsOptions): Source[] { @@ -169,7 +172,10 @@ export class GraphQLProjectConfig { return []; } - return this._extensionsRegistry.loaders.documents.loadDocumentsSync(pointer, options); + return this._extensionsRegistry.loaders.documents.loadDocumentsSync(pointer, { + ...options, + ignore: options?.ignore ? options?.ignore : this.exclude, + }); } // Rest diff --git a/test/config.spec.ts b/test/config.spec.ts index 9921f9d8f..2128ed2b6 100644 --- a/test/config.spec.ts +++ b/test/config.spec.ts @@ -1,5 +1,6 @@ import { buildSchema, buildASTSchema } from 'graphql'; import path from 'path'; +import { vi } from 'vitest'; import { TempDir } from './utils/temp-dir'; import { runTests } from './utils/runner'; import { loadConfig, loadConfigSync, ConfigNotFoundError, GraphQLConfig } from 'graphql-config'; @@ -275,6 +276,67 @@ runTests({ async: loadConfig, sync: loadConfigSync })((load, mode) => { expect(config.getProjectForFile('./foo/ignored/component.ts').name).toBe('bar'); }); + test.each(['loadDocumentsSync', 'loadDocuments'] as const)('%s uses exclude', async (method) => { + temp.createFile( + '.graphqlrc', + ` + projects: + foo: + schema: ./foo.graphql + include: ./foo/*.ts + exclude: ./foo/ignored/** + `, + ); + + const config = await load({ rootDir: temp.dir }); + + const project = config.getProject('foo'); + + const loadDocumentsSyncSpy = vi + .spyOn(project['_extensionsRegistry'].loaders.documents, method) + .mockReturnValue([]); + + await project[method]('./**/*'); + + expect(loadDocumentsSyncSpy).toHaveBeenCalledWith('./**/*', { + ignore: './foo/ignored/**', + }); + + loadDocumentsSyncSpy.mockRestore(); + }); + + test.each(['loadDocumentsSync', 'loadDocuments'] as const)( + '%s respects options.ignore when provided (overrides exclude)', + async (method) => { + temp.createFile( + '.graphqlrc', + ` + schema: ./schema.graphql + documents: ./**/*.graphql + exclude: + - "**/excluded/**" + `, + ); + + const config = await load({ rootDir: temp.dir }); + const project = config.getDefault(); + + const loadDocumentsSyncSpy = vi + .spyOn(project['_extensionsRegistry'].loaders.documents, method) + .mockReturnValue([]); + + // Call with custom ignore - should override exclude + await project[method]('./**/*.graphql', { ignore: '**/custom-ignored/**' }); + + // Verify it was called with custom ignore (NOT the exclude from config) + expect(loadDocumentsSyncSpy).toHaveBeenCalledWith('./**/*.graphql', { + ignore: '**/custom-ignored/**', + }); + + loadDocumentsSyncSpy.mockRestore(); + }, + ); + test('customizable config name', async () => { temp.createFile(schemaFilename, testSDL); temp.createFile('foo.config.js', `module.exports = { schema: '${schemaFilename}' }`);