diff --git a/.changeset/five-spies-impress.md b/.changeset/five-spies-impress.md
new file mode 100644
index 00000000000..0c6a04e4640
--- /dev/null
+++ b/.changeset/five-spies-impress.md
@@ -0,0 +1,5 @@
+---
+'@graphql-codegen/cli': major
+---
+
+Make @parcel/watcher optional
diff --git a/packages/graphql-codegen-cli/package.json b/packages/graphql-codegen-cli/package.json
index 4795b7c04df..b8275e8950c 100644
--- a/packages/graphql-codegen-cli/package.json
+++ b/packages/graphql-codegen-cli/package.json
@@ -55,7 +55,6 @@
"@graphql-tools/prisma-loader": "^8.0.0",
"@graphql-tools/url-loader": "^8.0.0",
"@graphql-tools/utils": "^10.0.0",
- "@parcel/watcher": "^2.1.0",
"@whatwg-node/fetch": "^0.8.0",
"chalk": "^4.1.0",
"cosmiconfig": "^8.1.3",
@@ -78,6 +77,7 @@
},
"devDependencies": {
"@graphql-tools/merge": "9.0.0",
+ "@parcel/watcher": "^2.1.0",
"@types/debounce": "1.2.1",
"@types/inquirer": "8.2.6",
"@types/is-glob": "4.0.2",
@@ -92,8 +92,14 @@
"prettier": "2.8.8"
},
"peerDependencies": {
+ "@parcel/watcher": "^2.1.0",
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
},
+ "peerDependenciesMeta": {
+ "@parcel/watcher": {
+ "optional": true
+ }
+ },
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
diff --git a/packages/graphql-codegen-cli/src/utils/watcher.ts b/packages/graphql-codegen-cli/src/utils/watcher.ts
index 40c077a1f08..a03b9438465 100644
--- a/packages/graphql-codegen-cli/src/utils/watcher.ts
+++ b/packages/graphql-codegen-cli/src/utils/watcher.ts
@@ -60,7 +60,17 @@ export const createWatcher = (
const runWatcher = async (abortSignal: AbortSignal) => {
const watchDirectory = await findHighestCommonDirectory(allAffirmativePatterns);
- const parcelWatcher = await import('@parcel/watcher');
+ // Try to load the parcel watcher, but don't fail if it's not available.
+ let parcelWatcher: typeof import('@parcel/watcher');
+ try {
+ parcelWatcher = await import('@parcel/watcher');
+ } catch (err) {
+ log(
+ `Parcel watcher not found. To use this feature, please make sure to provide @parcel/watcher as a peer dependency.`
+ );
+ return;
+ }
+
debugLog(`[Watcher] Parcel watcher loaded...`);
let isShutdown = false;
diff --git a/website/route-lockfile.txt b/website/route-lockfile.txt
index c70e4c729a0..a210f5f43ff 100644
--- a/website/route-lockfile.txt
+++ b/website/route-lockfile.txt
@@ -57,6 +57,7 @@
/docs/integrations/vscode
/docs/migration/from-0-13
/docs/migration/from-0-18
+/docs/migration/from-4-0
/docs/plugins -> /plugins
/docs/plugins/c-sharp -> /plugins/c-sharp/c-sharp-operations
/docs/plugins/client-note -> /plugins
diff --git a/website/src/pages/docs/getting-started/development-workflow.mdx b/website/src/pages/docs/getting-started/development-workflow.mdx
index 628f2408c8a..a0885609b02 100644
--- a/website/src/pages/docs/getting-started/development-workflow.mdx
+++ b/website/src/pages/docs/getting-started/development-workflow.mdx
@@ -2,6 +2,8 @@
description: How to integrate GraphQL Code Generator into your development workflow. Learn how to run it in watch mode, or as part of your CI flow.
---
+import { Callout } from '@theguild/components'
+
# Development workflow
GraphQL Code Generator should be integrated as part of your development workflow.
@@ -28,6 +30,13 @@ It's also helpful to run the codegen during your continuous integration flow and
## Watch Mode
+
+Watch mode was made optional to reduce install size in CI and prevent build errors in certain environments.
+
+To use watch mode, make sure to provide `@parcel/watcher` as a peer dependency.
+
+
+
If you wish to run the codegen in watch mode, you can specify `--watch` (or `-w`) when running it.
You can either run it in a separate terminal session or use tools like [`concurrently`](https://npmjs.com/package/concurrently) to run two scripts at the same time:
diff --git a/website/src/pages/docs/getting-started/installation.mdx b/website/src/pages/docs/getting-started/installation.mdx
index fdbdcfbadf7..057c77f76ac 100644
--- a/website/src/pages/docs/getting-started/installation.mdx
+++ b/website/src/pages/docs/getting-started/installation.mdx
@@ -14,6 +14,12 @@ npm i graphql
npm i -D typescript @graphql-codegen/cli
```
+If you want [watch mode](/docs/getting-started/development-workflow#watch-mode) support you need to add `@parcel/watcher` as well:
+
+```sh npm2yarn
+npm i -D @parcel/watcher
+```
+
## Global Installation
diff --git a/website/src/pages/docs/migration/_meta.json b/website/src/pages/docs/migration/_meta.json
index 6971ad2aafe..702e17b6a76 100644
--- a/website/src/pages/docs/migration/_meta.json
+++ b/website/src/pages/docs/migration/_meta.json
@@ -1,5 +1,6 @@
{
"graphql-cli": "GraphQL-CLI Deprecation",
"from-0-18": "v0.18 -> v1.0",
- "from-0-13": "v0.13 -> v0.17"
+ "from-0-13": "v0.13 -> v0.17",
+ "from-4-0": "v4.0 -> v5.0"
}
diff --git a/website/src/pages/docs/migration/from-4-0.mdx b/website/src/pages/docs/migration/from-4-0.mdx
new file mode 100644
index 00000000000..bf1005998b8
--- /dev/null
+++ b/website/src/pages/docs/migration/from-4-0.mdx
@@ -0,0 +1,95 @@
+---
+description: Migrating to 5.0.0. What has changed? How to migrate? What are the new features?
+---
+
+import { Tabs, Tab } from '@theguild/components'
+
+# Migration to 5.0.0
+
+## What has changed?
+
+There was an outstanding issue with `@parcel/watcher` which prevented it to be installed in certain environments, or needed an extra amount of dependencies to be built.
+This release focuses on improving the usage of `@graphql-codegen/cli` in those environments by making it an optional peer dependency.
+NPM (or Yarn) will not emit errors when an optional peer dependency is missing.
+
+## How to migrate?
+
+To use `@graphql-codegen/cli`'s watch mode (based on @parcel/watcher) you need to provide it in a package that uses `@graphql-codegen/cli` from now on.
+
+Start by updating your package.json
+
+
+
+```json filename="package.json"
+{
+ "devDependencies": {
+ "@graphql-codegen/cli": "^1.0.0",
+ "@graphql-codegen/typescript": "^1.0.0",
+ "@graphql-codegen/typescript-operations": "^1.0.0"
+ }
+}
+```
+
+
+
+```json filename="package.json"
+{
+ "devDependencies": {
+ "@graphql-codegen/cli": "^1.0.0",
+ "@graphql-codegen/typescript": "^1.0.0",
+ "@graphql-codegen/typescript-operations": "^1.0.0",
+ "@parcel/watcher": "^2.1.0"
+ }
+}
+```
+
+
+
+If you had issues with `@parcel/watcher` previously, you can make NPM and Yarn silently discard any build errors, by using `optionalDependencies` instead:
+
+
+
+```json filename="package.json"
+{
+ "devDependencies": {
+ "@graphql-codegen/cli": "^1.0.0",
+ "@graphql-codegen/typescript": "^1.0.0",
+ "@graphql-codegen/typescript-operations": "^1.0.0"
+ }
+}
+```
+
+
+
+```json filename="package.json"
+{
+ "devDependencies": {
+ "@graphql-codegen/cli": "^1.0.0",
+ "@graphql-codegen/typescript": "^1.0.0",
+ "@graphql-codegen/typescript-operations": "^1.0.0"
+ },
+ "optionalDependencies": {
+ "@parcel/watcher": "^2.1.0"
+ }
+}
+```
+
+
+
+```json filename="package.json"
+{
+ "devDependencies": {
+ "@graphql-codegen/cli": "^1.0.0",
+ "@graphql-codegen/typescript": "^1.0.0",
+ "@graphql-codegen/typescript-operations": "^1.0.0",
+ "@parcel/watcher": "^2.1.0"
+ },
+ "dependenciesMeta": {
+ "@parcel/watcher": {
+ "optional": true
+ }
+ }
+}
+```
+
+