enums don't seem to use the schema when they are properties in Zod
See original GitHub issueThe below types are generated.
/** The publications tags sort criteria */
export const TagSortCriteria = {
Alphabetical: 'ALPHABETICAL',
MostPopular: 'MOST_POPULAR',
} as const;
export type TagSortCriteria = typeof TagSortCriteria[keyof typeof TagSortCriteria];
export const TagSortCriteriaSchema = z.nativeEnum(TagSortCriteria);
export type AllPublicationsTagsRequest = {
cursor: InputMaybe<Scalars['Cursor']>;
limit: InputMaybe<Scalars['LimitScalar']>;
sort: TagSortCriteria;
/** The App Id */
source: InputMaybe<Scalars['Sources']>;
};
However it seems to generate AllPublicationsTagsRequest
with the wrong schema. I would expect it to use TagSortCriteriaSchema
as per your examples. I’m not sure if i have a wrong config.
export type AllPublicationsTagsRequest = {
cursor: InputMaybe<Scalars['Cursor']>;
limit: InputMaybe<Scalars['LimitScalar']>;
sort: TagSortCriteria;
/** The App Id */
source: InputMaybe<Scalars['Sources']>;
};
this is my config
const config: CodegenConfig = {
schema: 'https://api-sandbox-mumbai.lens.dev/',
documents: ['src/**/*.ts', '!src/generated/**/*'],
ignoreNoDocuments: true, // for better experience with the watcher
generates: {
'./src/generated/gql/gql.ts': {
// preset: [],
plugins: [
'typescript',
'typescript-operations',
'typescript-graphql-request',
'typescript-react-query',
'typescript-validation-schema',
{
add: {
content: '/* eslint-disable */',
},
},
{
add: {
content: 'import { ethers } from "ethers"',
},
},
{
add: {
content: ' ',
},
},
],
config: {
enumsAsConst: true,
maybeValue: 'T | undefined | null',
nonOptionalTypename: true,
useTypenameImports: true,
avoidOptionals: true,
schema: 'zod',
//strictScalars: true,
scalars: scalarDefinition,
enumAsTypes: true,
},
},
},
};
Issue Analytics
- State:
- Created a year ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Cannot read properties of undefined (reading '_parse') #1193
Hey, I've come across this issue in my project while composing schemas from imported zod objects/enums.Here is the code: CountryCode.ts ...
Read more >Creating a zod enum from an object - typescript - Stack Overflow
I want to define it only once using the properties object, without the VALUES array, and use it to create a zod object...
Read more >Untitled
This issue is resolved in zod@1.10.2 and later. --> # What is Zod Zod is a TypeScript-first schema declaration and validation library. I'm...
Read more >zod-to-json-schema - npm
Summary · Supports all relevant schema types, basic string, number and array length validations and string patterns. · Resolves recursive and ...
Read more >Safety Considerations When Using Enums in Avro Schemas
Avro is much loved because of its schema compatibility features. However, it turns out that use of the enum type can erode the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Code-Hex here is a reproduction: https://github.com/ShravanSunder/issue-graphql-zodgen please run
you’ll see the generated code in the generated folder
zod.ts
@ShravanSunder Thanks for creating the issue!
Could you share any information how to reproduce the problem. Thanks!