Skip to content

feat: support comment propagation from GraphQL to Zod describe#1416

Closed
CemYil03 wants to merge 1 commit intoCode-Hex:mainfrom
CemYil03:feat/comments
Closed

feat: support comment propagation from GraphQL to Zod describe#1416
CemYil03 wants to merge 1 commit intoCode-Hex:mainfrom
CemYil03:feat/comments

Conversation

@CemYil03
Copy link
Copy Markdown

Summary

  • Adds a new withDescriptions config option for zod and zodv4 schemas
  • When enabled, GraphQL description comments (triple-quote """...""") are passed through to Zod's .describe() method on both field-level and type-level schemas
  • Includes escaping for special characters (backslashes, single quotes, newlines)

Motivation

Zod's .describe() metadata is used by tools like Vercel's AI SDK to give LLMs context about each field when schemas are provided as tool inputs. Without this, AI models have no semantic understanding of what each field represents. This makes the plugin AI-ready by bridging GraphQL's rich type documentation into the generated validation schemas.

Example

"""A user input"""
input UserInput {
    """The user's name"""
    name: String!
}

generates:

export function UserInputSchema(): z.ZodObject<Properties<UserInput>> {
    return z.object({
        name: z.string().describe('The user\'s name')
    }).describe('A user input')
}

Test plan

  • Added tests for field-level descriptions, type-level descriptions, combined, disabled (false), special character escaping, and object types with withObjectType
  • Tests added for both zod and zodv4 visitors
  • TypeScript compilation passes with zero errors

@CemYil03
Copy link
Copy Markdown
Author

@Code-Hex @MH4GF @simonljus @elijaholmos could any of you find a few minutes for a code review please 😊

Copy link
Copy Markdown

@jbhurruth jbhurruth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I would love this feature to get in soon if my review means anything

@Code-Hex
Copy link
Copy Markdown
Owner

Code-Hex commented Apr 25, 2026

Closing this because the main part of the feature is now on main through #1423. withDescriptions: true emits Zod/Zod v4 field .describe(...) calls now, with tests and README coverage.

Your PR also covered type-level .describe(...) on the generated object schema. That did not land in #1423, and I do not want to pretend it did. I split that remaining piece into #1429 so it can be handled as a smaller follow-up instead of keeping this stale PR open.

Appreciate the patch. It helped clarify the shape of the feature.

@Code-Hex Code-Hex closed this Apr 25, 2026
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