Skip to content

Commit edacca9

Browse files
authored
Merge pull request #29 from yurks/fix/watch-nested-documents-and-schema
fix: watch documents and schemas from nested config
2 parents 9b2174a + 39f1361 commit edacca9

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

src/utils/configPaths.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import { normalizePath } from 'vite';
2+
import { resolve } from 'node:path';
23
import type { CodegenContext } from '@graphql-codegen/cli';
3-
import { normalizeInstanceOrArray } from '@graphql-codegen/plugin-helpers';
44

55
export async function getDocumentPaths(
66
context: CodegenContext,
77
): Promise<string[]> {
88
const config = context.getConfig();
99

10-
if (!config.documents) return [];
10+
const sourceDocuments = Object.values(config.generates).map((output) =>
11+
Array.isArray(output) ? undefined : output.documents,
12+
);
1113

12-
const normalized = normalizeInstanceOrArray(config.documents);
14+
if (config.documents) {
15+
sourceDocuments.unshift(config.documents);
16+
}
17+
18+
const normalized = sourceDocuments
19+
.filter((item): item is NonNullable<typeof item> => !!item)
20+
.flat();
21+
22+
if (!normalized.length) return [];
1323

1424
const documents = await context.loadDocuments(normalized);
1525

@@ -26,12 +36,23 @@ export async function getSchemaPaths(
2636
): Promise<string[]> {
2737
const config = context.getConfig();
2838

29-
if (!config.schema) return [];
39+
const sourceSchemas = Object.values(config.generates).map((output) =>
40+
Array.isArray(output) ? undefined : output.schema,
41+
);
42+
43+
if (config.schema) {
44+
sourceSchemas.unshift(config.schema);
45+
}
46+
47+
const schemas = sourceSchemas
48+
.filter((item): item is NonNullable<typeof item> => !!item)
49+
.flat();
3050

31-
const schemas = normalizeInstanceOrArray(config.schema);
51+
if (!schemas.length) return [];
3252

3353
return schemas
3454
.filter((schema): schema is string => typeof schema === 'string')
3555
.filter(Boolean)
56+
.map((schema) => resolve(schema))
3657
.map(normalizePath);
3758
}

0 commit comments

Comments
 (0)