Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,21 @@ 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,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted to make ignore override exclude incase people are already using ignore. A couple other options,

  • Merge ignore and exclude
  • Rename ignore to exclude
    • If exclude is passed as an option, should that be merged with this.exclude?

});
}

loadDocumentsSync(pointer: Pointer, options?: LoadTypedefsOptions): Source[] {
if (!pointer) {
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
Expand Down
62 changes: 62 additions & 0 deletions test/config.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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}' }`);
Expand Down