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.

Add option for generate original type too

See original GitHub issue

I know this plugin produces mutation validators in the first place, but can we have an option for original type as well? Nowadays we are not only uses zod for mutations, but also validates the data received from the server after fetching. I know I can just add the ID to the schema using zod’s extend, but it would be even more convenient if this plugin could do that.

type Member {
  id: ID!
  firstName: String
  lastName: String
}

type MemberInput {
  firstName: String
  lastName: String
}

// ->
// add this
export function MemberSchema(): z.ZodObject<Properties<Member>> {
  return z.object({
    id: z.string(),
    firstName: z.string().nullish(),
    lastName: z.string().nullish(),
  })
}

export function MemberInputSchema(): z.ZodObject<Properties<MemberInput>> {
  return z.object({
    firstName: z.string().nullish(),
    lastName: z.string().nullish(),
  })
}

so I can

import { graphQLClient, Member, MemberSchema } from "@/infra/graphql";

const getMembers = async (query = defaultQuery): Promise<Member[]> => {
  const { members } = await graphQLClient.request(query);

  const validatedData = MemberSchema().array().parse(members);
  // instead of 
  // const validatedData = MemberInputSchema().extend({ id: z.string() }).array().parse(members);

  return validatedData;
};

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Brian-McBridecommented, Jul 3, 2022

I needed the same thing. I opened a PR #109

1reaction
Code-Hexcommented, Jul 30, 2022

@anhdd-kuro @Brian-McBride Hi 👋

I just published the latest version v0.6.0 which is included this feature.

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can i change options in dropdowns if it is generated ...
My question is : If user selects an option from first dropdown then the options in the other two dropdowns should change according...
Read more >
How to Add / Remove Options of a Selection Box Dynamically
1) Using the Option constructor and add() method. First, use the Option constructor to create a new option with the specified option text...
Read more >
crunch - generate wordlists from a character set
If your original command used the -s option you MUST remove it before you resume the session. Just add -r to the end...
Read more >
Adding variants - Shopify Help Center
You add variants to a product that has more than one option, ... If you've already created a product, you can add options...
Read more >
typing — Support for type hints — Python 3.11.1 documentation
Source code: Lib/typing.py This module provides runtime support for type hints. The most fundamental support consists of the types Any, Union, Callable, ...
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