Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,40 @@ jobs:
- name: End2End Test Examples
run: |
EXAMPLE_TYPE=normal yarn examples:test:end2end
dev-tests-swc:
name: Examples - SWC
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup env
uses: the-guild-org/shared-config/setup@main
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
with:
toolchain: 1.65.0
target: wasm32-wasi
override: true
- name: Build SWC plugin
working-directory: ./packages/presets/swc-plugin
run: |
npm run build-wasm
- name: Build
run: yarn build
env:
CI: true
- name: Generate and Diff Codegen Artifacts
run: |
EXAMPLE_TYPE=swc yarn examples:codegen
git diff --exit-code -- examples/
- name: Build Examples
run: |
EXAMPLE_TYPE=swc yarn examples:build
- name: End2End Test Examples
run: |
EXAMPLE_TYPE=swc yarn examples:test:end2end

# TODO: Remove all SWC test setup and references as that has been moved to https://github.com/swc-project/plugins/tree/main/contrib/graphql-codegen-client-preset
# dev-tests-swc:
# name: Examples - SWC
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
# - name: Setup env
# uses: the-guild-org/shared-config/setup@main
# - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
# with:
# toolchain: 1.65.0
# target: wasm32-wasi
# override: true
# - name: Build SWC plugin
# working-directory: ./packages/presets/swc-plugin
# run: |
# npm run build-wasm
# - name: Build
# run: yarn build
# env:
# CI: true
# - name: Generate and Diff Codegen Artifacts
# run: |
# EXAMPLE_TYPE=swc yarn examples:codegen
# git diff --exit-code -- examples/
# - name: Build Examples
# run: |
# EXAMPLE_TYPE=swc yarn examples:build
# - name: End2End Test Examples
# run: |
# EXAMPLE_TYPE=swc yarn examples:test:end2end

esm:
name: Testing exports integrity
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion examples/persisted-documents-string-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"devDependencies": {
"@graphql-typed-document-node/core": "3.2.0",
"@graphql-codegen/cli": "6.0.0",
"@graphql-codegen/cli": "6.0.1",
"@babel/core": "7.25.2",
"@babel/preset-env": "7.25.3",
"@babel/preset-typescript": "7.27.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/persisted-documents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"devDependencies": {
"@graphql-typed-document-node/core": "3.2.0",
"@graphql-codegen/cli": "6.0.0",
"@graphql-codegen/cli": "6.0.1",
"@babel/core": "7.25.2",
"@babel/preset-env": "7.25.3",
"@babel/preset-typescript": "7.27.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/react/apollo-client-defer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"graphql-yoga": "5.7.0"
},
"devDependencies": {
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@types/node": "^22.0.0",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.10",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/apollo-client-swc-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"devDependencies": {
"@graphql-codegen/client-preset-swc-plugin": "0.2.0",
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@vitejs/plugin-react-swc": "^3.3.0",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/apollo-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@vitejs/plugin-react": "^4.0.0",
"@types/node": "^22.0.0",
"@types/react": "^18.0.15",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/http-executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@vitejs/plugin-react": "^4.0.0",
"@types/node": "^22.0.0",
"@types/react": "^18.0.17",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/nextjs-swr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"swr": "^2.0.0"
},
"devDependencies": {
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@graphql-codegen/schema-ast": "5.0.0",
"@graphql-codegen/client-preset-swc-plugin": "0.2.0",
"@types/node": "^22.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/tanstack-react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@vitejs/plugin-react": "^4.0.0",
"@types/node": "^22.0.0",
"@types/react": "^18.0.17",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/urql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.10",
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@vitejs/plugin-react": "^4.0.0",
"typescript": "5.5.4",
"serve": "14.2.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"devDependencies": {
"@graphql-codegen/cli": "6.0.0"
"@graphql-codegen/cli": "6.0.1"
},
"dependencies": {
"@graphql-typed-document-node/core": "3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"devDependencies": {
"@graphql-codegen/cli": "6.0.0"
"@graphql-codegen/cli": "6.0.1"
},
"dependencies": {
"graphql": "16.9.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-resolvers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"devDependencies": {
"@graphql-codegen/cli": "6.0.0",
"@graphql-codegen/cli": "6.0.1",
"@graphql-codegen/typescript": "5.0.2",
"@graphql-codegen/typescript-resolvers": "5.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/vite-react-cts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"vite": "^6.0.0"
},
"devDependencies": {
"@graphql-codegen/cli": "6.0.0",
"@graphql-codegen/cli": "6.0.1",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"cypress": "14.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/vite-react-mts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"vite": "^6.0.0"
},
"devDependencies": {
"@graphql-codegen/cli": "6.0.0",
"@graphql-codegen/cli": "6.0.1",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"cypress": "14.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/vite-react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"vite": "^6.0.0"
},
"devDependencies": {
"@graphql-codegen/cli": "6.0.0",
"@graphql-codegen/cli": "6.0.1",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"cypress": "14.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/apollo-composable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"vue": "^3.2.37"
},
"devDependencies": {
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@vitejs/plugin-vue": "^5.0.0",
"typescript": "^5.0.0",
"vite": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/urql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"vue": "^3.2.45"
},
"devDependencies": {
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@vitejs/plugin-vue": "^5.0.0",
"typescript": "^5.0.0",
"vite": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/villus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"vue": "^3.2.37"
},
"devDependencies": {
"@graphql-codegen/cli": "^6.0.0",
"@graphql-codegen/cli": "^6.0.1",
"@vitejs/plugin-vue": "^5.0.0",
"typescript": "^5.0.0",
"vite": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/yoga-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"devDependencies": {
"@graphql-typed-document-node/core": "3.2.0",
"@graphql-codegen/cli": "6.0.0",
"@graphql-codegen/cli": "6.0.1",
"@babel/core": "7.25.2",
"@babel/preset-env": "7.25.3",
"@babel/preset-typescript": "7.27.1"
Expand Down
12 changes: 12 additions & 0 deletions packages/graphql-codegen-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @graphql-codegen/cli

## 6.0.1

### Patch Changes

- [#10468](https://github.com/dotansimha/graphql-code-generator/pull/10468) [`cb1b9d9`](https://github.com/dotansimha/graphql-code-generator/commit/cb1b9d99c413a96fde6c9af0b2315b3ad721ee4e) Thanks [@eddeee888](https://github.com/eddeee888)! - In watch mode, do not write output on failure

Previously, on partial or full failure, watch mode still write to output. However, since the output'd be an empty array, it will then call `removeStaleFiles` internally to remove all previously generated files.

This patch puts a temporary fix to avoid writing output on any failure to fix the described behaviour.

This also means the `config.allowPartialOutputs` does not work in watch mode for now.

## 6.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-codegen-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/cli",
"version": "6.0.0",
"version": "6.0.1",
"license": "MIT",
"bin": {
"gql-gen": "dist/cjs/bin.js",
Expand Down
11 changes: 9 additions & 2 deletions packages/graphql-codegen-cli/src/generate-and-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ const hash = (content: string): string => createHash('sha1').update(content).dig
export async function generate(
input: CodegenContext | (Types.Config & { cwd?: string }),
saveToFile = true
): Promise<Types.FileOutput[] | any> {
): Promise<
| Types.FileOutput[]
/**
* When this function runs in watch mode, it'd return an empty promise that doesn't resolve until the watcher exits
* FIXME: this effectively makes the result `any`, which loses type-hints
*/
| any
> {
const context = ensureContext(input);
const config = context.getConfig();
await context.profiler.run(() => lifecycleHooks(config.hooks).afterStart(), 'Lifecycle: afterStart');
Expand Down Expand Up @@ -43,7 +50,7 @@ export async function generate(

const recentOutputHash = new Map<string, string>();

async function writeOutput(generationResult: Types.FileOutput[]) {
async function writeOutput(generationResult: Types.FileOutput[]): Promise<Types.FileOutput[]> {
if (!saveToFile) {
return generationResult;
}
Expand Down
25 changes: 23 additions & 2 deletions packages/graphql-codegen-cli/src/utils/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,21 @@ export const createWatcher = (
if (!isShutdown) {
executeCodegen(initialContext)
.then(
({ result }) => onNext(result),
({ result, error }) => {
// FIXME: this is a quick fix to stop `onNext` (writeOutput) from
// removing all files when there is an error.
//
// This is because `removeStaleFiles()` will remove files if the
// generated files are different between runs. And on error, it
// returns an empty array i.e. will remove all generated files from
// the previous run
//
// This also means we don't have config.allowPartialOutputs in watch mode
if (error) {
return;
}
onNext(result);
},
() => Promise.resolve()
)
.then(() => emitWatching(watchDirectory));
Expand Down Expand Up @@ -202,7 +216,14 @@ export const createWatcher = (
stopWatching.runningWatcher = new Promise<void>((resolve, reject) => {
executeCodegen(initialContext)
.then(
({ result }) => onNext(result),
({ result, error }) => {
// TODO: this is the initial run, the logic here mimics the above watcher logic.
// We need to check whether it's ok to deviate between these two.
if (error) {
return;
}
onNext(result);
},
() => Promise.resolve()
)
.then(() => runWatcher(abortController.signal))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join, isAbsolute, relative, resolve, sep } from 'path';
import { Options } from '@parcel/watcher';
import type { Options } from '@parcel/watcher';
import isGlob from 'is-glob';
import type { Mock } from 'vitest';

Expand All @@ -22,7 +22,7 @@ interface MockWatcher {

/**
* Helper function for asserting that multiple paths did or did not trigger a build,
* and for asserting the values of paths and globs passed to {@link ParcelWatcher.Options}`["ignore"]`
* and for asserting the values of paths and globs passed to {@link Options}`["ignore"]`
*/
export const assertBuildTriggers = async (
mockWatcher: MockWatcher,
Expand Down Expand Up @@ -224,7 +224,7 @@ const assertParcelWouldIgnoreGlob = (
};

/**
* Given a path, and the `ignore` option passed to the mocked {@link ParcelWatcher.Options},
* Given a path, and the `ignore` option passed to the mocked {@link Options},
* assert that ParcelWatcher "would" ignore the path if given it as part of the ignore option.
*
* Note that ParcelWatcher expects paths relative from the watchDirectory, but
Expand Down
Loading
Loading