Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-owls-guard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/core': patch
---

Skip documents without a `document` AST when validating documents against the schema, instead of passing `undefined` to validation. Generated output from the CLI is unchanged.
9 changes: 5 additions & 4 deletions packages/graphql-codegen-core/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,18 @@ export async function codegen(options: Types.GenerateOptions): Promise<string> {
rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)),
);
const schemaHash = extractHashFromSchema(schemaInstance);
const documentHashes = transformedDocuments.map(d => d.hash);

if (
!schemaHash ||
!options.cache ||
transformedDocuments.some(d => typeof d.hash !== 'string')
!documentHashes.every((hash): hash is string => typeof hash === 'string')
Comment thread
eddeee888 marked this conversation as resolved.
Outdated
) {
return Promise.resolve(
validateGraphQlDocuments(
schemaInstance,
[
...transformedDocuments.flatMap(d => d.document),
...transformedDocuments.flatMap(d => (d.document ? [d.document] : [])),
...fragments.flatMap(f => f.document),
],
rules,
Expand All @@ -154,7 +155,7 @@ export async function codegen(options: Types.GenerateOptions): Promise<string> {
}

const cacheKey = [schemaHash]
.concat(transformedDocuments.map(doc => doc.hash))
.concat(documentHashes)
.concat(JSON.stringify(fragments))
.join(',');

Expand All @@ -163,7 +164,7 @@ export async function codegen(options: Types.GenerateOptions): Promise<string> {
validateGraphQlDocuments(
schemaInstance,
[
...transformedDocuments.flatMap(d => d.document),
...transformedDocuments.flatMap(d => (d.document ? [d.document] : [])),
...fragments.flatMap(f => f.document),
],
rules,
Expand Down
5 changes: 3 additions & 2 deletions packages/graphql-codegen-core/src/execute-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ export async function executePlugin(
const pluginContext = options.pluginContext || {};
const profiler = options.profiler ?? createNoopProfiler();

if (plugin.validate && typeof plugin.validate === 'function') {
Comment thread
eddeee888 marked this conversation as resolved.
const validate = plugin.validate?.bind(plugin);
if (validate && typeof validate === 'function') {
try {
// FIXME: Sync validate signature with plugin signature
await profiler.run(
async () =>
plugin.validate(
validate(
outputSchema,
documents,
options.config,
Expand Down
Loading