From 5f8f08d4b64fe53db9ce485695bb108f27db8cc6 Mon Sep 17 00:00:00 2001 From: yurk Date: Fri, 7 Jun 2024 14:24:58 +0300 Subject: [PATCH 1/2] fix: watch documents and schemas from nested config --- src/utils/configPaths.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/utils/configPaths.ts b/src/utils/configPaths.ts index 32bc0d4..da25d5e 100644 --- a/src/utils/configPaths.ts +++ b/src/utils/configPaths.ts @@ -1,15 +1,24 @@ import { normalizePath } from 'vite'; import type { CodegenContext } from '@graphql-codegen/cli'; -import { normalizeInstanceOrArray } from '@graphql-codegen/plugin-helpers'; export async function getDocumentPaths( context: CodegenContext, ): Promise { const config = context.getConfig(); - if (!config.documents) return []; + const sourceDocuments = Object.values(config.generates).map((output) => + Array.isArray(output) ? undefined : output.documents, + ); - const normalized = normalizeInstanceOrArray(config.documents); + if (config.documents) { + sourceDocuments.unshift(config.documents); + } + + const normalized = sourceDocuments + .filter((item): item is NonNullable => !!item) + .flat(); + + if (!normalized.length) return []; const documents = await context.loadDocuments(normalized); @@ -26,9 +35,19 @@ export async function getSchemaPaths( ): Promise { const config = context.getConfig(); - if (!config.schema) return []; + const sourceSchemas = Object.values(config.generates).map((output) => + Array.isArray(output) ? undefined : output.schema, + ); + + if (config.schema) { + sourceSchemas.unshift(config.schema); + } + + const schemas = sourceSchemas + .filter((item): item is NonNullable => !!item) + .flat(); - const schemas = normalizeInstanceOrArray(config.schema); + if (!schemas.length) return []; return schemas .filter((schema): schema is string => typeof schema === 'string') From 39f136140018175357eec47ef7846b12103d95af Mon Sep 17 00:00:00 2001 From: yurk Date: Fri, 7 Jun 2024 16:24:00 +0300 Subject: [PATCH 2/2] chore: normalize schema file path --- src/utils/configPaths.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/configPaths.ts b/src/utils/configPaths.ts index da25d5e..b2971e6 100644 --- a/src/utils/configPaths.ts +++ b/src/utils/configPaths.ts @@ -1,4 +1,5 @@ import { normalizePath } from 'vite'; +import { resolve } from 'node:path'; import type { CodegenContext } from '@graphql-codegen/cli'; export async function getDocumentPaths( @@ -52,5 +53,6 @@ export async function getSchemaPaths( return schemas .filter((schema): schema is string => typeof schema === 'string') .filter(Boolean) + .map((schema) => resolve(schema)) .map(normalizePath); }