Skip to content

Conversation

@Brian-McBride
Copy link

This will allow the support of a schema with a type:

type User {
  id: ID
  name: String
  email: String
  password: String
  createdAt: Date
  updatedAt: Date
}

to generate an expected validator

Yup:

export function UserSchema(): yup.SchemaOf<User> {
  return yup.object({
    __typename: yup.mixed().oneOf(['User', undefined]),
    createdAt: yup.mixed(),
    email: yup.string(),
    id: yup.string(),
    name: yup.string(),
    password: yup.string(),
    updatedAt: yup.mixed()
  })
}

Zod:

export function UserSchema(): z.ZodObject<Properties<User>> {
  return z.object({
    __typename: z.literal('User').optional(),
    createdAt: definedNonNullAnySchema.nullish(),
    email: z.string().nullish(),
    id: z.string().nullish(),
    name: z.string().nullish(),
    password: z.string().nullish(),
    updatedAt: definedNonNullAnySchema.nullish()
  })
}

MyZod:

export function UserSchema(): myzod.Type<User> {
  return myzod.object({
    __typename: myzod.literal('User').optional(),
    createdAt: definedNonNullAnySchema.optional().nullable(),
    email: myzod.string().optional().nullable(),
    id: myzod.string().optional().nullable(),
    name: myzod.string().optional().nullable(),
    password: myzod.string().optional().nullable(),
    updatedAt: definedNonNullAnySchema.optional().nullable()
  })
}

This config will trigger the creation of graphql `type` objects into validation schemas.
@Code-Hex
Copy link
Owner

Code-Hex commented Jul 4, 2022

@Brian-McBride Wow, great your PR!

Could you add tests for object types followed as same as input types? Thank you so much!

@Brian-McBride
Copy link
Author

I'll add in some unit tests later next week. I am a bit slammed for the next couple of days.

@anhdd-kuro
Copy link
Contributor

anhdd-kuro commented Jul 18, 2022

@Brian-McBride
Sorry for asking but is there any update on this ?

@Code-Hex
Copy link
Owner

@Brian-McBride Ping ^

@Brian-McBride
Copy link
Author

@Brian-McBride Sorry for asking but is there any update on this ?

I am sorry all. I have not had any time to get to the unit tests. I am hoping to have time later this week. Just slammed with deliverables currently.

@Code-Hex
Copy link
Owner

@Brian-McBride Thanks your reply!

However I don't have time to watch this PR too, so I will close this PR next Tuesday (JST).

Thanks 😊

@anhdd-kuro
Copy link
Contributor

@Code-Hex
I tried to write some test
Plz check #132

@Code-Hex Code-Hex closed this Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants