Skip to content

Filter empty files to prevent GraphQL codegen plugin configuration errors#393

Merged
eddeee888 merged 5 commits intoeddeee888:masterfrom
sammwafy:fix/pluginmap-reference
Nov 30, 2025
Merged

Filter empty files to prevent GraphQL codegen plugin configuration errors#393
eddeee888 merged 5 commits intoeddeee888:masterfrom
sammwafy:fix/pluginmap-reference

Conversation

@sammwafy
Copy link
Copy Markdown
Contributor

Fix GraphQL Codegen Plugin Configuration Issues

Issue

The GraphQL codegen was failing if files included in tsconfig were empty:
Invalid plugin configuration: Empty source files were being processed, causing the add plugin to fail with:

Configuration provided for 'add' plugin is invalid: "content" is missing!

Solution

✅ Filter out empty source files

  • Added .filter() to skip files with no meaningful content before processing
  • Prevents invalid plugin configurations from empty files
return tsProject.getSourceFiles()
  .filter((sf) => sf.getFullText().trim().length > 0)  // ← just add a filter for empty files
  .map((tsSourceFile) => ({
    filename: tsSourceFile.getFilePath(),
    pluginMap: { add: addPlugin },  // ← Fixed reference
    plugins: [{ add: { content: tsSourceFile.getFullText() } }],
    config: {},
    schema,
    documents: [],
  }));

Results

  • ✅ Prevents empty/invalid plugin outputs
  • Tested locally with both src/test/*.tsx and src/**/*.tsx includes — codegen now runs successfully without errors

Testing

Verified the fix works with multiple file patterns and confirmed no regressions in existing functionality.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Sep 25, 2025

🦋 Changeset detected

Latest commit: 36f2525

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@eddeee888/gcg-operation-location-migration Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@stefanoruth
Copy link
Copy Markdown

Have the same issue, this fixed it.

@eddeee888
Copy link
Copy Markdown
Owner

Hi @sammwafy !
Thanks for the fix. I'm curious in which scenario this is happening and whether we can write a test for it?

@sammwafy
Copy link
Copy Markdown
Contributor Author

Hi @eddeee888
This happens when there are empty files in the project. Since content is required by the add plugin, even one empty file will cause the whole codegen process to fail.
this becomes an issue in large projects with many files so we can just filters out empty files before processing.

@eddeee888
Copy link
Copy Markdown
Owner

Hi @sammwafy ,

Thanks for the details, may I ask when it would get to this situation? I've tried this on my side but cannot reproduce it.

@eddeee888
Copy link
Copy Markdown
Owner

Thank you @sammwafy !
I got confused between the plugins. This fixes the issue 🙌

I've added a test and fixed a few files for the release

@eddeee888 eddeee888 merged commit f084ebe into eddeee888:master Nov 30, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants