apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 467 forks source link

client:codegen fails on windows with Error: No operations or fragments found to generate code for #2667

Open Zikoat opened 1 year ago

Zikoat commented 1 year ago

Problem

After updating apollo to 2.34.0, i get an error on windows when generating typescript code:

Error: Command failed: apollo client:codegen --localSchemaFile=C:\companyname\__generated__\schema.json,C:\companyname\src\clientSchema.graphql --target=typescript --includes=C:\companyname\src\**\*.graphql --globalTypesFile=./__generated__/globalTypes.ts --suppressDeprecationWarning --excludes=C:\companyname\src\clientSchema.graphql

⚠️  It looks like there are 0 files associated with this Apollo Project. This may be because you don't have any files yet, or your includes/excludes fields are configured incorrectly, andd Apollo can't find your files. For help configuring Apollo projects, see this guide: https://go.apollo.dev/t/config

    Error: No operations or fragments found to generate code for.

Solution

Change backslashes to forwardslashes.

-npx apollo client:codegen --localSchemaFile=C:/company/__generated__/schema.json,C:/company/src/clientSchema.graphql --target=typescript --includes=C:/company/src/**/*.graphql --globalTypesFile=./__generated__/globalTypes.ts --suppressDeprecationWarning --excludes=C:/company/src/clientSchema.graphql;
+npx apollo client:codegen --localSchemaFile=C:\company\__generated__\schema.json,C:\company\src\clientSchema.graphql --target=typescript --includes=C:\company\src\**\*.graphql --globalTypesFile=./__generated__/globalTypes.ts --suppressDeprecationWarning --excludes=C:\company\src\clientSchema.graphql;

Why does this happen?

apollo@2.34.0 uses apollo-language-server@1.26.9 which upgrades glob from ^7.1.3 to ^8.0.0, which has a breaking change which makes it use backslashes as escape characters instead of path separators on windows.

A fix would be to normalize the paths to unix-style using the normalize-path package before using glob to find files to transform, but because this package is deprecated i just wanted to document a potential fix for this error.