Skip to content

Conversation

javan-b
Copy link
Contributor

@javan-b javan-b commented May 10, 2025

This update enhances the registerEnum function to support richer metadata for enum values using registerEnumType from @nestjs/graphql.

✅ Features
• Adds a valuesMap derived from SchemaEnum value documentation (e.g., comments in schema.prisma)
• Parses @deprecated annotations to set deprecationReason
• Uses regular comments as description
• Skips enum values without comments
• Introduces extractEnumValueDocs helper to encapsulate parsing logic

javan-b added 2 commits May 10, 2025 17:40
Enhances the `registerEnum` function to include per-enum-value descriptions and deprecation reasons when registering enums using `registerEnumType`.  - Introduces a `valuesMap` generated from the `SchemaEnum` value documentation (e.g., comments in schema.prisma). - Deprecation reasons are parsed from `@deprecated` annotations. - Regular comments are used as descriptions for enum values. - Values without comments are skipped in the `valuesMap`. - Includes a helper `extractEnumValueDocs` to isolate parsing logic.  Example: /// @deprecated Use USER instead ADMIN → becomes: ADMIN: { deprecationReason: "Use USER instead" }  This allows richer metadata in GraphQL schema introspection and enhances tooling and client generation.  Usage remains backward compatible for enums without documentation.
@javan-b
Copy link
Contributor Author

javan-b commented May 10, 2025

// @generated/prisma/role.enum.ts

import { registerEnumType } from '@nestjs/graphql';

export enum Role {
USER = "USER",
NINGA = "NINGA",
ADMIN = "ADMIN",
REVIEWER = "REVIEWER"
}

registerEnumType(Role, { name: 'Role', description: "user access control", valuesMap: {
USER: {
description: "default user access control"
},
NINGA: {
description: "have full access control"
},
ADMIN: {
deprecationReason: "Use USER instead"
}
} })

@unlight unlight merged commit 4a2d0d7 into unlight:master May 11, 2025
2 checks passed
Copy link

🎉 This PR is included in version 21.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants