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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"ts-jest": "29.4.9",
"typescript": "6.0.3",
"valibot": "1.3.1",
"vitest": "^3.2.4",
"vitest": "^4.0.0",
"yup": "1.7.1",
"zod": "4.3.6"
}
Expand Down
685 changes: 301 additions & 384 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { isNamedType } from './graphql.js';

/**
* Wraps a schema expression in a library-specific lazy reference when the type
* is a complex (non-scalar, non-enum) named type avoiding issues with
* is a complex (non-scalar, non-enum) named type, avoiding issues with
* mutually-recursive input types.
*
* Each validation library has its own lazy syntax (z.lazy, v.lazy, etc.), so
* callers supply the wrapper function.
*
* @param visitor - Type lookup used to distinguish scalars/enums from complex types.
* @param type - GraphQL type node for the schema expression.
* @param schema - Generated schema expression to wrap when needed.
* @param lazyWrapper - e.g. `(s) => \`z.lazy(() => ${s})\``
*/
export function buildMaybeLazy(
Expand Down
4 changes: 2 additions & 2 deletions src/zod/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ObjectTypeDefinitionBuilder,
} from '../graphql.js';
import { BaseSchemaVisitor } from '../schema_visitor.js';
import { buildZodOperationSchemas } from './operation.js';
import {
anySchema,
buildObjectExpression,
Expand All @@ -31,7 +30,8 @@ import {
schemaDepthVariable,
unionLiterals,
withDescription,
} from './shared.js';
} from '../zod_shared.js';
import { buildZodOperationSchemas } from './operation.js';

export class ZodSchemaVisitor extends BaseSchemaVisitor {
constructor(schema: GraphQLSchema, config: ValidationSchemaPluginConfig) {
Expand Down
12 changes: 6 additions & 6 deletions src/zod/shared.ts → src/zod_shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ import type {
TypeNode,
} from 'graphql';

import type { ValidationSchemaPluginConfig } from '../config.js';
import type { Visitor } from '../visitor.js';
import type { ValidationSchemaPluginConfig } from './config.js';
import type { Visitor } from './visitor.js';
import { resolveExternalModuleAndFn } from '@graphql-codegen/plugin-helpers';
import { convertNameParts, indent } from '@graphql-codegen/visitor-plugin-common';
import {
isInputObjectType,
Kind,
valueFromASTUntyped,
} from 'graphql';
import { buildApi, formatDirectiveConfig } from '../directive.js';
import { buildApi, formatDirectiveConfig } from './directive.js';
import {
escapeGraphQLCharacters,
isListType,
isNamedType,
isNonNullType,
} from '../graphql.js';
import { buildMaybeLazy } from '../lazy.js';
import { buildScalarSchema } from '../scalar.js';
} from './graphql.js';
import { buildMaybeLazy } from './lazy.js';
import { buildScalarSchema } from './scalar.js';

export const anySchema = `definedNonNullAnySchema`;

Expand Down
2 changes: 1 addition & 1 deletion src/zodv4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
schemaDepthVariable,
unionLiterals,
withDescription,
} from '../zod/shared.js';
} from '../zod_shared.js';

export class ZodV4SchemaVisitor extends BaseSchemaVisitor {
constructor(schema: GraphQLSchema, config: ValidationSchemaPluginConfig) {
Expand Down
19 changes: 0 additions & 19 deletions tests/helpers/plugin.ts

This file was deleted.

87 changes: 0 additions & 87 deletions tests/helpers/schemas.ts

This file was deleted.

9 changes: 9 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { createRequire } from 'node:module';
import { defineConfig } from 'vitest/config';

const require = createRequire(import.meta.url);

export default defineConfig({
resolve: {
alias: {
graphql: require.resolve('graphql/index.js'),
},
},
test: {
globals: true,
environment: 'node',
Expand All @@ -9,6 +17,7 @@ export default defineConfig({
exclude: ['node_modules', 'dist', 'example', '.idea', '.git', '.cache', '.github'],
server: {
deps: {
external: ['graphql'],
fallbackCJS: true,
},
},
Expand Down
Loading