Skip to content

Commit ddd7b21

Browse files
committed
Fix tests
1 parent 8dacdf6 commit ddd7b21

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
"[rust]": {
2828
"editor.defaultFormatter": "rust-lang.rust-analyzer",
2929
"editor.formatOnSave": true
30-
}
30+
},
31+
"js/ts.tsdk.path": "node_modules/typescript/lib"
3132
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export class CodegenContext {
392392
this._config = config;
393393
this._graphqlConfig = graphqlConfig;
394394
this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
395-
this.cwd = this._graphqlConfig ? this._graphqlConfig.dirpath : process.cwd();
395+
this.cwd = this._graphqlConfig ? this._graphqlConfig.dirpath : config?.cwd || process.cwd();
396396
this.profiler = createNoopProfiler();
397397
}
398398

@@ -416,10 +416,19 @@ export class CodegenContext {
416416
}
417417
}
418418

419-
return {
419+
const config = {
420420
...extraConfig,
421421
...this.config,
422422
};
423+
424+
if (this._graphqlConfig) {
425+
return config;
426+
}
427+
428+
return {
429+
...config,
430+
cwd: this.cwd,
431+
};
423432
}
424433

425434
updateConfig(config: Partial<Types.Config>): void {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export async function loadDocuments(
8787
// we omit paths that don't resolve to a specific file
8888
continue;
8989
}
90-
ignore.push(join(process.cwd(), generatePath));
90+
ignore.push(join(config.cwd || process.cwd(), generatePath));
9191
}
9292

9393
try {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,8 @@ describe('Codegen Executor', () => {
12901290
watch: false,
12911291
});
12921292
const config = prj1.getConfig();
1293-
const { result } = await executeCodegen(config);
1293+
const { result, error } = await executeCodegen(config);
1294+
expect(error).toBeFalsy();
12941295
expect(result[0].content).toContain('DocumentNode<MyQueryQuery, MyQueryQueryVariables>');
12951296
});
12961297

packages/utils/plugins-helpers/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ export namespace Types {
552552
* @description If `true`, write to files whichever `generates` block succeeds. If `false`, one failed `generates` means no output is written to files. Default: false
553553
*/
554554
allowPartialOutputs?: boolean;
555+
/**
556+
* Working directory
557+
*/
558+
cwd?: string;
555559
}
556560

557561
export type ComplexPluginOutput<M = Record<string, unknown>> = {

0 commit comments

Comments
 (0)