Skip to content

Commit

Permalink
Merge pull request #29 from yurks/fix/watch-nested-documents-and-schema
Browse files Browse the repository at this point in the history
fix: watch documents and schemas from nested config
  • Loading branch information
danielwaltz authored Jun 12, 2024
2 parents 9b2174a + 39f1361 commit edacca9
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/utils/configPaths.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { normalizePath } from 'vite';
import { resolve } from 'node:path';
import type { CodegenContext } from '@graphql-codegen/cli';
import { normalizeInstanceOrArray } from '@graphql-codegen/plugin-helpers';

export async function getDocumentPaths(
context: CodegenContext,
): Promise<string[]> {
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<typeof item> => !!item)
.flat();

if (!normalized.length) return [];

const documents = await context.loadDocuments(normalized);

Expand All @@ -26,12 +36,23 @@ export async function getSchemaPaths(
): Promise<string[]> {
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<typeof item> => !!item)
.flat();

const schemas = normalizeInstanceOrArray(config.schema);
if (!schemas.length) return [];

return schemas
.filter((schema): schema is string => typeof schema === 'string')
.filter(Boolean)
.map((schema) => resolve(schema))
.map(normalizePath);
}

0 comments on commit edacca9

Please sign in to comment.