From aecf3768c84a3e29b8af0d8963f20916a8049236 Mon Sep 17 00:00:00 2001 From: Jonatan Witoszek Date: Thu, 26 Jan 2023 11:04:06 +0100 Subject: [PATCH] Fix issues with build-types, when feature flags are used (#3043) --- scripts/build-types.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/build-types.js b/scripts/build-types.js index ed3a5b09a..697012a0a 100644 --- a/scripts/build-types.js +++ b/scripts/build-types.js @@ -39,7 +39,7 @@ for (const rawSuffix of schemaSuffixes) { ], }, [getOutputPath("types", suffix)]: { - documents: getDocumentsPaths(suffix), + documents: getDocumentsPaths(suffix, rawSuffix), config: { nonOptionalTypename: true, avoidOptionals: { @@ -64,7 +64,7 @@ for (const rawSuffix of schemaSuffixes) { ], }, [getOutputPath("hooks", suffix)]: { - documents: getDocumentsPaths(suffix), + documents: getDocumentsPaths(suffix, rawSuffix), preset: "import-types", presetConfig: { typesPath: "./types" + suffix + ".generated", @@ -92,12 +92,18 @@ function getOutputPath(path, suffix) { return `./src/graphql/${path}${suffix}.generated.ts`; } -function getDocumentsPaths(suffix) { +function getDocumentsPaths(suffix, rawSuffix) { return [ `./src/**/queries${suffix}.ts`, `./src/**/mutations${suffix}.ts`, `./src/**/fragments/*${suffix}.ts`, `./src/searches/*${suffix}.ts`, + // Remove feature flag files from default suffix (matches glob) + ...FEATURE_FLAGS.filter(flag => flag !== rawSuffix).map( + flag => `!./src/**/*${prepareSuffix(flag)}.ts`, + ), + // Always add all fragments (e.g. Money) + ...(rawSuffix !== "default" ? ["./src/**/fragments/*.ts"] : []), ]; }