Skip to content

[RFC] Better resolver validation and authorization with a new pipe function #1787

Answered by flybayer
flybayer asked this question in RFCs
Discussion options

You must be logged in to vote

Update!

Here's the final result. I had to have a little wrapper for zod schemas to make the types correct, so decided to make pipe and object that we can add various utilities to. Currently has pipe.resolver, pipe.zod, and pipe.authorize

This is fully working both for strong types and runtime! :)

😍😍😍😍😍😍

import {pipe} from "blitz"
import db from "db"
import * as z from "zod"

export const CreateProject = z.object({
  name: z.string(),
  dueDate: z.date().optional(),
  orgId: z.number().optional(),
})

export default pipe.resolver(
  pipe.zod(CreateProject),
  pipe.authorize(),
  // Set default orgId
  (input, {session}) => ({orgId: session.orgId, ...input}),
  async (input, ctx) => {

    c…

Replies: 5 comments 2 replies

Comment options

flybayer
Jan 23, 2021
Maintainer Author

You must be logged in to vote
0 replies
Comment options

flybayer
Jan 23, 2021
Maintainer Author

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@flybayer
Comment options

flybayer Jan 24, 2021
Maintainer Author

Comment options

You must be logged in to vote
0 replies
Comment options

flybayer
Jan 26, 2021
Maintainer Author

You must be logged in to vote
1 reply
@flybayer
Comment options

flybayer Jan 26, 2021
Maintainer Author

Answer selected by flybayer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants