dotansimha / dotansimha/graphql-code-generator

Plugin `schema-ast` is not found when using workspaces in Yarn 3

Open
#7,691 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

Following the request of @ardatan, I have set a **minimal example** which reproduces the error on [GitHub](https://github.com/Poolshark/issue-graphql-codegen). Unfortunately I could not figure out how to use the CodeSandbox example with Yarn 3 but I'm hoping my repo will do the job too.

#### [1] - Minimal Example
- The minimal example repo can be found here: https://github.com/Poolshark/issue-graphql-codegen

- It's set to **zero install** so everything should work out of the box. But you might want to run `yarn cache clear && yarn install` just to be sure.

- Since I'm using **VSCode**, the `@yarnpkg/sdks` is set to `vscode`. If you use another IDE you have to install the appropriate SDK.

- Run the test with `yarn run:script tools/scripts/src/test.ts` to reproduce the error.

#### [2] - Running the test
When running the test the following error occurs:
```
✔ Parse configuration
✔ Parse configuration
❯ Generate outputs
❯ Generate ./__generated__/schema.graphql
✔ Load GraphQL schemas
✔ Load GraphQL documents
✖ Generate
→ Unable to find template plugin matching schema-ast

Found 1 error

✖ ./__generated__/schema.graphql
Unable to find template plugin matching 'schema-ast'
Install one of the following packages:

- @graphql-codegen/schema-ast
- @graphql-codegen/schema-ast-template
- @graphql-codegen/schema-ast-plugin
- graphql-codegen-schema-ast
- graphql-codegen-schema-ast-template
- graphql-codegen-schema-ast-plugin
- codegen-schema-ast
- codegen-schema-ast-template
- schema-ast
Error: Unable to find template plugin matching schema-ast
```
---

## Bug description
Schema generation from remote schema using `@graphql-codegen/cli` with Yarn 3 workspaces fails because the plugin `schema-ast` can't be found. It works with Yarn 3 with the same folder structure if workspaces are disabled.

#### The Test Script I'm trying to run
```ts
import { generate } from "@graphql-codegen/cli";

generate(
{
overwrite: true,
generates: {
["./__generated__/schema.graphql"]: {
schema: `https://nameless-brook-330181.eu-central-1.aws.cloud.dgraph.io/graphql`,
plugins: ["schema-ast"],
},
},
},
true
);
```

#### The `package.json` in the monorepo root
```json
{
"name": "monorepo",
"packageManager": "yarn@3.2.0",
"devDependencies": {
"ts-node": "^10.7.0",
"typescript": "^4.6.2"
},
"workspaces": [
"frontend/*",
"tools/*"
],
"scripts": {
"run:script": "ts-node ${0}"
}
}
```

#### The `package.json` in the `scripts` package
```json
{
"name": "@tools/scripts",
"packageManager": "yarn@3.2.0",
"dependencies": {
"@graphql-codegen/cli": "^2.6.2",
"@graphql-codegen/schema-ast": "^2.4.1",
"@types/node": "^17.0.23",
"graphql": "^16.3.0"
}
}
```

## Expected behaviour
I expect the script to generate a file `schema.graphql` inside the folder `__generated__`.

## Environment

- OS: macOS Monterey v12.3
- `@graphql-codegen/cli`: 2.6.2
- `@graphql-codegen/schema-ast`: 2.4.1
- `ts-node`: 10.7.0
- NodeJS: 17.2.0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.