Skip to content

Commit

Permalink
example of #703
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Jul 23, 2021
1 parent ea47bd4 commit b3427be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/next-prisma-starter/package.json
Expand Up @@ -41,7 +41,8 @@
"react-query": "^3.6.0",
"start-server-and-test": "^1.12.0",
"superjson": "^1.7.4",
"zod": "^3.0.0"
"zod": "^3.0.0",
"zod-to-json-schema": "^3.0.1"
},
"devDependencies": {
"@types/jest": "^26.0.23",
Expand Down
7 changes: 7 additions & 0 deletions examples/next-prisma-starter/src/server/routers/posts.ts
Expand Up @@ -5,6 +5,7 @@

import { createRouter } from 'server/trpc';
import { z } from 'zod';
import zodToJsonSchema from 'zod-to-json-schema';

export const postsRouter = createRouter()
// create
Expand Down Expand Up @@ -58,6 +59,12 @@ export const postsRouter = createRouter()
return todo;
},
})
.query('edit.input', {
resolve() {
const schema: any = (postsRouter._def.mutations.edit as any).inputParser;
return zodToJsonSchema(schema, 'edit.input');
},
})
// delete
.mutation('delete', {
input: z.string().uuid(),
Expand Down
13 changes: 10 additions & 3 deletions yarn.lock
Expand Up @@ -3006,7 +3006,7 @@
resolved "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.3.tgz#781d360c282436494b32fe7d9f7f8e64b3118aa3"
integrity sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw==

"@typescript-eslint/eslint-plugin@^4.11.1", "@typescript-eslint/eslint-plugin@^4.25.0":
"@typescript-eslint/eslint-plugin@^4.25.0":
version "4.28.4"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.28.4.tgz#e73c8cabbf3f08dee0e1bda65ed4e622ae8f8921"
integrity sha512-s1oY4RmYDlWMlcV0kKPBaADn46JirZzvvH7c2CtAqxCY96S538JRBAzt83RrfkDheV/+G/vWNK0zek+8TB3Gmw==
Expand All @@ -3031,7 +3031,7 @@
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"

"@typescript-eslint/parser@^4.11.1", "@typescript-eslint/parser@^4.20.0", "@typescript-eslint/parser@^4.26.0":
"@typescript-eslint/parser@^4.20.0", "@typescript-eslint/parser@^4.26.0":
version "4.28.4"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.28.4.tgz#bc462dc2779afeefdcf49082516afdc3e7b96fab"
integrity sha512-4i0jq3C6n+og7/uCHiE6q5ssw87zVdpUj1k6VlVYMonE3ILdFApEzTWgppSRG4kVNB/5jxnH+gTeKLMNfUelQA==
Expand Down Expand Up @@ -13299,7 +13299,14 @@ zen-observable@^0.8.15:
resolved "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.15.tgz#96415c512d8e3ffd920afd3889604e30b9eaac15"
integrity sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==

zod@^3.0.0:
zod-to-json-schema@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.0.1.tgz#471605e7006077b7ae79e3f2ce77191374882585"
integrity sha512-NTRChq7Y+KZgCQP9K7F1OHPEMKQVMeh6MqWYAne9DgyqGAkKztGGp3jrrEj2oPrnKwuVK+kAFS4BH04eQc+FHw==
dependencies:
zod "^3.2.0"

zod@^3.0.0, zod@^3.2.0:
version "3.5.1"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.5.1.tgz#e93ce58e182bb76f7d29ccd24feee72611f9a129"
integrity sha512-Gg9GTai0iDHowuYM9VNhdFMmesgt44ufzqaE5CPHshpuK5fCzbibdqCnrWuYH6ZmOn/N+BlGmwZtVSijhKmhKw==

0 comments on commit b3427be

Please sign in to comment.