Skip to content

Commit d487e0c

Browse files
Merge GraphQL and Vitest updates (#1428)
* Move shared Zod helpers and remove unused test helpers * chore(deps): update dependency graphql to v16.13.2 * chore(deps): update dependency vitest to v4 * test: align GraphQL resolution for Vitest 4 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 635394e commit d487e0c

9 files changed

Lines changed: 324 additions & 501 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"ts-jest": "29.4.9",
102102
"typescript": "6.0.3",
103103
"valibot": "1.3.1",
104-
"vitest": "^3.2.4",
104+
"vitest": "^4.0.0",
105105
"yup": "1.7.1",
106106
"zod": "4.3.6"
107107
}

pnpm-lock.yaml

Lines changed: 301 additions & 384 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lazy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import { isNamedType } from './graphql.js';
66

77
/**
88
* Wraps a schema expression in a library-specific lazy reference when the type
9-
* is a complex (non-scalar, non-enum) named type avoiding issues with
9+
* is a complex (non-scalar, non-enum) named type, avoiding issues with
1010
* mutually-recursive input types.
1111
*
1212
* Each validation library has its own lazy syntax (z.lazy, v.lazy, etc.), so
1313
* callers supply the wrapper function.
1414
*
15+
* @param visitor - Type lookup used to distinguish scalars/enums from complex types.
16+
* @param type - GraphQL type node for the schema expression.
17+
* @param schema - Generated schema expression to wrap when needed.
1518
* @param lazyWrapper - e.g. `(s) => \`z.lazy(() => ${s})\``
1619
*/
1720
export function buildMaybeLazy(

src/zod/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
ObjectTypeDefinitionBuilder,
1919
} from '../graphql.js';
2020
import { BaseSchemaVisitor } from '../schema_visitor.js';
21-
import { buildZodOperationSchemas } from './operation.js';
2221
import {
2322
anySchema,
2423
buildObjectExpression,
@@ -31,7 +30,8 @@ import {
3130
schemaDepthVariable,
3231
unionLiterals,
3332
withDescription,
34-
} from './shared.js';
33+
} from '../zod_shared.js';
34+
import { buildZodOperationSchemas } from './operation.js';
3535

3636
export class ZodSchemaVisitor extends BaseSchemaVisitor {
3737
constructor(schema: GraphQLSchema, config: ValidationSchemaPluginConfig) {
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ import type {
1212
TypeNode,
1313
} from 'graphql';
1414

15-
import type { ValidationSchemaPluginConfig } from '../config.js';
16-
import type { Visitor } from '../visitor.js';
15+
import type { ValidationSchemaPluginConfig } from './config.js';
16+
import type { Visitor } from './visitor.js';
1717
import { resolveExternalModuleAndFn } from '@graphql-codegen/plugin-helpers';
1818
import { convertNameParts, indent } from '@graphql-codegen/visitor-plugin-common';
1919
import {
2020
isInputObjectType,
2121
Kind,
2222
valueFromASTUntyped,
2323
} from 'graphql';
24-
import { buildApi, formatDirectiveConfig } from '../directive.js';
24+
import { buildApi, formatDirectiveConfig } from './directive.js';
2525
import {
2626
escapeGraphQLCharacters,
2727
isListType,
2828
isNamedType,
2929
isNonNullType,
30-
} from '../graphql.js';
31-
import { buildMaybeLazy } from '../lazy.js';
32-
import { buildScalarSchema } from '../scalar.js';
30+
} from './graphql.js';
31+
import { buildMaybeLazy } from './lazy.js';
32+
import { buildScalarSchema } from './scalar.js';
3333

3434
export const anySchema = `definedNonNullAnySchema`;
3535

src/zodv4/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
schemaDepthVariable,
3333
unionLiterals,
3434
withDescription,
35-
} from '../zod/shared.js';
35+
} from '../zod_shared.js';
3636

3737
export class ZodV4SchemaVisitor extends BaseSchemaVisitor {
3838
constructor(schema: GraphQLSchema, config: ValidationSchemaPluginConfig) {

tests/helpers/plugin.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/helpers/schemas.ts

Lines changed: 0 additions & 87 deletions
This file was deleted.

vitest.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
import { createRequire } from 'node:module';
12
import { defineConfig } from 'vitest/config';
23

4+
const require = createRequire(import.meta.url);
5+
36
export default defineConfig({
7+
resolve: {
8+
alias: {
9+
graphql: require.resolve('graphql/index.js'),
10+
},
11+
},
412
test: {
513
globals: true,
614
environment: 'node',
@@ -9,6 +17,7 @@ export default defineConfig({
917
exclude: ['node_modules', 'dist', 'example', '.idea', '.git', '.cache', '.github'],
1018
server: {
1119
deps: {
20+
external: ['graphql'],
1221
fallbackCJS: true,
1322
},
1423
},

0 commit comments

Comments
 (0)