Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
graphql-codegen-typescript-validation-schema
Advanced tools
GraphQL Code Generator plugin to generate form validation schema from your GraphQL schema
GraphQL code generator plugin to generate form validation schema from your GraphQL schema.
Start by installing this plugin and write simple plugin config;
$ npm i graphql-codegen-typescript-validation-schema
generates:
path/to/graphql.ts:
plugins:
- typescript
- typescript-validation-schema # specify to use this plugin
config:
# You can put the config for typescript plugin here
# see: https://www.graphql-code-generator.com/plugins/typescript
strictScalars: true
# You can also write the config for this plugin together
schema: yup
You can check example directory if you want to check more complex config example or how is generated some files.
schema
type: ValidationSchema
default: 'yup'
Specify generete validation schema you want.
generates:
path/to/graphql.ts:
plugins:
- typescript
- graphql-codegen-validation-schema
config:
schema: yup
importFrom
type: string
import types from generated typescript type path. if not given, omit import statement.
generates:
path/to/graphql.ts:
plugins:
- typescript
path/to/validation.ts:
plugins:
- graphql-codegen-validation-schema
config:
importFrom: ./graphql # path for generated ts code
Then the generator generates code with import statement like below.
import { GeneratedInput } from './graphql'
/* generates validation schema here */
enumsAsTypes
type: boolean
default: false
Generates enum as TypeScript type
instead of enum
.
directives
type: DirectiveConfig
Generates validation schema with more API based on directive schema. For example, yaml config and GraphQL schema is here.
generates:
path/to/graphql.ts:
plugins:
- typescript
- graphql-codegen-validation-schema
config:
schema: yup
directives:
required:
msg: required
constraint:
minLength: min
# Replace $1 with specified `startsWith` argument value of the constraint directive
startsWith: ["matches", "/^$1/"]
format:
email: email
input ExampleInput {
email: String! @required(msg: "Hello, World!") @constraint(minLength: 50)
message: String! @constraint(startsWith: "Hello")
}
Then generates yup validation schema like below.
export function ExampleInputSchema(): yup.SchemaOf<ExampleInput> {
return yup.object({
email: yup.string().defined().required("Hello, World!").min(50),
message: yup.string().defined().matches(/^Hello/)
})
}
FAQs
GraphQL Code Generator plugin to generate form validation schema from your GraphQL schema
The npm package graphql-codegen-typescript-validation-schema receives a total of 34,393 weekly downloads. As such, graphql-codegen-typescript-validation-schema popularity was classified as popular.
We found that graphql-codegen-typescript-validation-schema demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.