Skip to content

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

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

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 😊

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.

1 participant