@graphql-codegen/cli 6.0.0 → 6.0.1-alpha-20251020115833-8d7877f21dec8264954784745fe577eccf6bb9da

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,7 +48,21 @@ const createWatcher = (initialContext, onNext) => {
48
48
  const debouncedExec = (0, debounce_1.default)(() => {
49
49
  if (!isShutdown) {
50
50
  (0, codegen_js_1.executeCodegen)(initialContext)
51
- .then(({ result }) => onNext(result), () => Promise.resolve())
51
+ .then(({ result, error }) => {
52
+ // FIXME: this is a quick fix to stop `onNext` (writeOutput) from
53
+ // removing all files when there is an error.
54
+ //
55
+ // This is because `removeStaleFiles()` will remove files if the
56
+ // generated files are different between runs. And on error, it
57
+ // returns an empty array i.e. will remove all generated files from
58
+ // the previous run
59
+ //
60
+ // This also means we don't have config.allowPartialOutputs in watch mode
61
+ if (error) {
62
+ return;
63
+ }
64
+ onNext(result);
65
+ }, () => Promise.resolve())
52
66
  .then(() => emitWatching(watchDirectory));
53
67
  }
54
68
  }, 100);
@@ -146,7 +160,14 @@ const createWatcher = (initialContext, onNext) => {
146
160
  */
147
161
  stopWatching.runningWatcher = new Promise((resolve, reject) => {
148
162
  (0, codegen_js_1.executeCodegen)(initialContext)
149
- .then(({ result }) => onNext(result), () => Promise.resolve())
163
+ .then(({ result, error }) => {
164
+ // TODO: this is the initial run, the logic here mimics the above watcher logic.
165
+ // We need to check whether it's ok to deviate between these two.
166
+ if (error) {
167
+ return;
168
+ }
169
+ onNext(result);
170
+ }, () => Promise.resolve())
150
171
  .then(() => runWatcher(abortController.signal))
151
172
  .catch(err => {
152
173
  watcherSubscription.unsubscribe();
@@ -44,7 +44,21 @@ export const createWatcher = (initialContext, onNext) => {
44
44
  const debouncedExec = debounce(() => {
45
45
  if (!isShutdown) {
46
46
  executeCodegen(initialContext)
47
- .then(({ result }) => onNext(result), () => Promise.resolve())
47
+ .then(({ result, error }) => {
48
+ // FIXME: this is a quick fix to stop `onNext` (writeOutput) from
49
+ // removing all files when there is an error.
50
+ //
51
+ // This is because `removeStaleFiles()` will remove files if the
52
+ // generated files are different between runs. And on error, it
53
+ // returns an empty array i.e. will remove all generated files from
54
+ // the previous run
55
+ //
56
+ // This also means we don't have config.allowPartialOutputs in watch mode
57
+ if (error) {
58
+ return;
59
+ }
60
+ onNext(result);
61
+ }, () => Promise.resolve())
48
62
  .then(() => emitWatching(watchDirectory));
49
63
  }
50
64
  }, 100);
@@ -142,7 +156,14 @@ export const createWatcher = (initialContext, onNext) => {
142
156
  */
143
157
  stopWatching.runningWatcher = new Promise((resolve, reject) => {
144
158
  executeCodegen(initialContext)
145
- .then(({ result }) => onNext(result), () => Promise.resolve())
159
+ .then(({ result, error }) => {
160
+ // TODO: this is the initial run, the logic here mimics the above watcher logic.
161
+ // We need to check whether it's ok to deviate between these two.
162
+ if (error) {
163
+ return;
164
+ }
165
+ onNext(result);
166
+ }, () => Promise.resolve())
146
167
  .then(() => runWatcher(abortController.signal))
147
168
  .catch(err => {
148
169
  watcherSubscription.unsubscribe();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "6.0.0",
3
+ "version": "6.0.1-alpha-20251020115833-8d7877f21dec8264954784745fe577eccf6bb9da",
4
4
  "peerDependenciesMeta": {
5
5
  "@parcel/watcher": {
6
6
  "optional": true
@@ -2,4 +2,9 @@ import { Types } from '@graphql-codegen/plugin-helpers';
2
2
  import { CodegenContext } from './config.cjs';
3
3
  export declare function generate(input: CodegenContext | (Types.Config & {
4
4
  cwd?: string;
5
- }), saveToFile?: boolean): Promise<Types.FileOutput[] | any>;
5
+ }), saveToFile?: boolean): Promise<Types.FileOutput[]
6
+ /**
7
+ * When this function runs in watch mode, it'd return an empty promise that doesn't resolve until the watcher exits
8
+ * FIXME: this effectively makes the result `any`, which loses type-hints
9
+ */
10
+ | any>;
@@ -2,4 +2,9 @@ import { Types } from '@graphql-codegen/plugin-helpers';
2
2
  import { CodegenContext } from './config.js';
3
3
  export declare function generate(input: CodegenContext | (Types.Config & {
4
4
  cwd?: string;
5
- }), saveToFile?: boolean): Promise<Types.FileOutput[] | any>;
5
+ }), saveToFile?: boolean): Promise<Types.FileOutput[]
6
+ /**
7
+ * When this function runs in watch mode, it'd return an empty promise that doesn't resolve until the watcher exits
8
+ * FIXME: this effectively makes the result `any`, which loses type-hints
9
+ */
10
+ | any>;