Skip to content

Commit

Permalink
feat: use custom app prefix for default codegen configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lgandecki committed Apr 1, 2021
1 parent 73fb0ee commit 86ecf07
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import * as fs from 'fs';
import { findProjectMainPath } from '../generate/helpers/findProjectMainPath';
import { newTask, ListrRenderer } from '../generate/helpers/ListrHelper';

const runTypeGen = async (projectMainPath: string) => {
const runTypeGen = async (projectMainPath: string, appPrefix: string) => {
const customCodegenConfig = path.join(projectMainPath, './codegen.js');
let codegenConfigPath;
if (fs.existsSync(customCodegenConfig)) {
codegenConfigPath = customCodegenConfig;
} else {
codegenConfigPath = path.join(__dirname, '../generate/runtime-config-helpers/codegen.js');
}
await execQuietly(`npx graphql-codegen --config ${codegenConfigPath}`, { cwd: projectMainPath });
await execQuietly(`APP_PREFIX=${appPrefix} npx graphql-codegen --config ${codegenConfigPath}`, {
cwd: projectMainPath,
});
};

const fixGenerated = async (projectMainPath: string) => {
Expand Down Expand Up @@ -68,7 +70,7 @@ export default class Generate extends Command {
newTask('Generating code', async () =>
executeGeneration(flags.appPrefix, flags.generatedPrefix, flags.modulesPath),
),
newTask('Generating types', async () => runTypeGen(projectMainPath)),
newTask('Generating types', async () => runTypeGen(projectMainPath, flags.appPrefix)),
newTask('Tweak the generated types', async () => fixGenerated(projectMainPath)),
newTask('Prettify the generated code', async () => prettifyGenerated(projectMainPath, flags.modulesPath)),
],
Expand Down
2 changes: 1 addition & 1 deletion src/generate/runtime-config-helpers/getCodegenConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = function ({ contextType } = {}) {
generates: {
'generated/graphql/types.ts': {
config: {
contextType: contextType || '~app/context#GqlContext',
contextType: contextType || `${process.env.APP_PREFIX}/context#GqlContext`,
idFieldName: 'id',
objectIdType: 'string',
federation: true,
Expand Down

0 comments on commit 86ecf07

Please sign in to comment.