Skip to content

Commit e173e11

Browse files
ya2sCodexeddeee888
authored
fix(cli): forward nested graphql-config loader options (#10590)
* fix(cli): align graphql-config loader options with codegen config Ensure nested `config` values (e.g. inputValueDeprecation) are forwarded when loading schema/documents via GraphQL Config. Add a regression test covering nested config forwarding on the GraphQL Config path. Related #9659 Co-Authored-By: Codex <codex@localhost> * chore(changeset): add patch release for cli config forwarding fix Co-Authored-By: Codex <codex@localhost> * Fix changeset --------- Co-authored-by: Codex <codex@localhost> Co-authored-by: Eddy Nguyen <[email protected]> Co-authored-by: Eddy Nguyen <[email protected]>
1 parent db3b790 commit e173e11

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

.changeset/tame-panthers-rule.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphql-codegen/cli": patch
3+
---
4+
5+
Fix GraphQL Config loading to forward nested `extensions.codegen.config` options
6+
when loading schemas/documents, matching `codegen.ts` behavior.

packages/graphql-codegen-cli/src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ export class CodegenContext {
444444
if (this._graphqlConfig) {
445445
// TODO: SchemaWithLoader won't work here
446446
return addHashToSchema(
447-
this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config)
447+
this._graphqlConfig
448+
.getProject(this._project)
449+
.loadSchema(pointer, 'GraphQLSchema', { ...config, ...config.config })
448450
);
449451
}
450452
return addHashToSchema(loadSchema(pointer, config));
@@ -454,7 +456,9 @@ export class CodegenContext {
454456
const config = this.getConfig(defaultDocumentsLoadOptions);
455457
if (this._graphqlConfig) {
456458
// TODO: pointer won't work here
457-
return addHashToDocumentFiles(this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config));
459+
return addHashToDocumentFiles(
460+
this._graphqlConfig.getProject(this._project).loadDocuments(pointer, { ...config, ...config.config })
461+
);
458462
}
459463

460464
return addHashToDocumentFiles(loadDocuments(pointer, config));

packages/graphql-codegen-cli/tests/config.spec.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { createContext, ensureContext } from '../src/index.js';
1+
import { buildSchema } from 'graphql';
2+
import { createContext, ensureContext, CodegenContext } from '../src/index.js';
23

34
describe('Codegen config - Context', () => {
45
it('loads and merge multiple schemas when using GraphQL config', async () => {
@@ -86,4 +87,36 @@ describe('Codegen config - Context', () => {
8687
expect(typeMap['DateTime']).toBeDefined();
8788
expect(typeMap['User']).toBeDefined();
8889
});
90+
91+
it('passes nested config values to graphql-config schema loader', async () => {
92+
const loadSchemaSpy = vi.fn().mockResolvedValue(buildSchema('type Query { _: Boolean }'));
93+
const project = {
94+
extension: vi.fn().mockReturnValue({
95+
generates: {},
96+
config: {
97+
inputValueDeprecation: true,
98+
},
99+
}),
100+
schema: ['http://example.com/graphql'],
101+
documents: [],
102+
loadSchema: loadSchemaSpy,
103+
loadDocuments: vi.fn(),
104+
};
105+
const graphqlConfig = {
106+
filepath: '/tmp/graphql.config.ts',
107+
dirpath: '/tmp',
108+
getProject: vi.fn().mockReturnValue(project),
109+
} as any;
110+
111+
const context = new CodegenContext({ graphqlConfig });
112+
await context.loadSchema(['http://example.com/graphql']);
113+
114+
expect(loadSchemaSpy).toHaveBeenCalledWith(
115+
['http://example.com/graphql'],
116+
'GraphQLSchema',
117+
expect.objectContaining({
118+
inputValueDeprecation: true,
119+
})
120+
);
121+
});
89122
});

0 commit comments

Comments
 (0)