question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docs on integrating with other OSS

See original GitHub issue

It would be nice to have docs on how to integrate zod with other OSS. This would help people:

  • identify whether zod will work well with their tech stack
  • figure out how to use zod with their tech stack
  • help zod validate its feature set. If the docs are hard to write, zod is probably missing something.

GraphQL

It seems like zod could be well suited for GraphQL validations. It would be handy to have a reference for the parallels of GraphQL types and their corresponding zod types, as well as any other suggestions for integrating zod into the GraphQL environment.

As a single small example:

union Fish = Salmon | Tuna | Trout
type Catch {
  fish: Fish!
}
const FishEnum = z.union([z.literal('Salmon'), z.literal('Tuna'), z.literal('Trout')]);
const Catch = z.object({
  fish: FishEnum,
});

Of course it’s a bit less obvious when it comes to nullable types because GraphQL is nullable by default, and zod is required by default.

React PropTypes

Seems like an integration that would make sense for libraries. Similar docs like those for GraphQL could make sense.

formik

Formik has native support for Yup schemas. Docs on integrating zod with formik would be nice!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
ivosabevcommented, Nov 17, 2020

Formik integration would be nice, especially with Formik V3 coming soon.

4reactions
ryardleycommented, Aug 19, 2020

So far this works for me getting Zod to work with Formik (only semi-tested).

import * as z from 'zod'

class ValidationError extends Error {
  public name = 'ValidationError'
  inner: { path: string; message: string }[]
}

function createValidationError(e: z.ZodError) {
  const error = new ValidationError(e.message)
  error.inner = Object.keys(e.errors).map((k) => ({
    message: e.errors[k].message,
    path: e.errors[k].path.join('.'),
  }))
  return error
}


// Wrap your zod schema before passing it to Formik's `validationSchema` prop
export function toFormikYupSchema(schema: z.ZodSchema<any>) {
  return {
    async validate(obj: any) {
      try {
        await Promise.resolve(schema.parse(obj))
      } catch (err) {
        throw createValidationError(err)
      }
    },
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docs on integrating with other OSS · Issue #86 · colinhacks/zod
I think it's a good idea to create a new INTEGRATIONS.md file in the repo describing best practices/patterns for integrating Zod with other...
Read more >
7 Integration Features - Oracle Help Center
This chapter describes the features of Oracle Communications IP Service Activator that enable it to integrate with other OSS applications.
Read more >
OS Integration - web.dev
OS Integration. Your PWA now works outside the browser. This chapter covers how to integrate further with the operating system once users install...
Read more >
Integration enablement - Next-Generation OSS with AWS
Integration enablement aligns with the increasing focus of implementing modular OSS applications exposed via Open APIs, and the need to support dynamic ...
Read more >
The Top-5 OSS/BSS Integration Things
Rarely does a new OSS application live in isolation. Integration with other systems in the OSS and BSS environment could easily be as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found