graphql-codegen-yup
v1.0.12
Published
Forked from graphql-codegen-typescript-validation-schema. Added support for fragments and some other typing support. Was initially going to include it there, but zod is a bit borked on nested typing, so I just added a this lib for yup.
Downloads
6
Maintainers
Readme
graphql-codegen-yup
Graphql codegen plugin for yup schema generation.
Links
Github
https://github.com/strynkow/graphql-codegen-yup/tree/master
NPM
https://www.npmjs.com/package/graphql-codegen-yup
Overview
The TLDR here is that I was looking at graphql-codegen-typescript-validation-schema
, but it didn't really support fragments, and that caused it to break on object types. I was going to add that, but zod was incorrectly erroring on types (seemed to be a zod issue), so I just added my own project for yup.
I plan on actively maintaining this. Feel free to contribute.
Install
NPM
npm i --save-dev graphql-codegen-yup
Yarn
yarn add -D graphql-codegen-yup
Use
Once you've installed the package, you can add it to your current codegen config in the following manner.
generates:
path/to/graphql.ts:
plugins:
- typescript
- graphql-codegen-yup # add this line.
config:
# For overwriting any schemas with specific values.
scalarSchemas:
JSON: yup.object()
Date: yup.date()
Email: yup.string().email()
You can see test cases and examples by browsing around the /tests
folder. /tests/__snapshots__
contains the outputs of running this on those schemas.