apollographql / apollographql/apollo-tooling

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

Open
#2,667 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

## 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.
```diff
-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](https://github.com/isaacs/node-glob/issues/467) 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](https://www.npmjs.com/package/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.

Contributor guide

Open the contributing guide

Research direction

Start at the apollo client:codegen entry point and trace how --includes and --excludes paths are passed to glob, with the glob 8 Windows behavior described in the issue. Reproduce the command on Windows using the shown schema and GraphQL paths, then verify that operations and fragments are found and TypeScript code is generated.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.