Conversation
- Introduced the AuthenticatedUser type in both API schemas, enhancing user data representation. - Implemented a resolver for AuthenticatedUser to handle user retrieval and fallback for missing first names. - Updated user object exports to include AuthenticatedUser for better federation support.
- Added the AuthenticatedUser type to the API schemas, including fields for user details. - Extended the AuthenticatedUser type to support federation with external services. - Updated generated TypeScript definitions to reflect the new structure of AuthenticatedUser. - Modified user-related GraphQL operations to incorporate the new AuthenticatedUser type.
- Updated the AuthenticatedUser type in the API schemas to include federation capabilities with the API_JOURNEYS_MODERN graph. - Introduced a new external reference for AuthenticatedUser in the user schema to facilitate integration. - Modified TypeScript exports to include the new AuthenticatedUser reference for improved type handling.
WalkthroughThis PR introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit 1125224
☁️ Nx Cloud last updated this comment at |
|
The latest updates on your projects.
|
|
The latest updates on your projects.
|
|
The latest updates on your projects.
|
|
The latest updates on your projects.
|
|
The latest updates on your projects.
|
|
The latest updates on your projects.
|
|
The latest updates on your projects.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apis/api-users/src/schema/user/user.ts`:
- Around line 49-82: The error log and duplicated resolver should be fixed by
extracting the shared logic into a helper (e.g., resolveUserReference) that
performs prisma.user.findUnique({ where: { userId: id } }), handles missing
user, applies the firstName fallback ('Unknown User') when null/empty, and
catches/logs errors; update the AuthenticatedUser.builder.asEntity
resolveReference to call this helper and change the catch log to mention
"AuthenticatedUser" (or include the entity name) rather than the generic "User",
and replace the duplicated resolveReference in the User entity to reuse the same
helper so both entities share identical behavior.
🧹 Nitpick comments (1)
apis/api-users/src/schema/user/objects/user.ts (1)
29-57: Extract sharedfirstNameresolver to reduce duplication.The
firstNameresolver (lines 33-45) is duplicated from theUserobject (lines 7-19). Consider extracting this into a shared helper function to maintain consistency and reduce maintenance burden.Additionally, the email field handling differs between
UserandAuthenticatedUser:
User: throws ifexposeStringwithnullable: false)AuthenticatedUser: returns empty string viauser.email ?? ''Returning an empty string may mask data integrity issues. Consider using consistent behavior or documenting the intentional difference.
♻️ Proposed refactor to extract shared resolver
import { builder } from '../../builder' +const resolveFirstName = (user: { firstName: string | null; userId: string }) => { + if (!user.firstName || user.firstName.trim() === '') { + console.warn( + `User ${user.userId} has invalid firstName: "${user.firstName}", using fallback` + ) + return 'Unknown User' + } + return user.firstName +} + export const User = builder.prismaObject('User', { name: 'User', fields: (t) => ({ id: t.exposeID('id', { nullable: false }), firstName: t.field({ type: 'String', nullable: false, - resolve: (user) => { - // Additional safeguard for firstName field - if (!user.firstName || user.firstName.trim() === '') { - console.warn( - `User ${user.userId} has invalid firstName: "${user.firstName}", using fallback` - ) - return 'Unknown User' - } - return user.firstName - } + resolve: resolveFirstName }),Apply the same change to
AuthenticatedUser.
- Deleted the AuthenticatedUser type definition from the GraphQL schema to streamline user data representation. - This change simplifies the API by removing unnecessary complexity related to user authentication details.
- Updated the branch name validation regex to allow for a broader range of naming conventions. - Added `createdAt` and `updatedAt` fields to various schema test cases to ensure timestamps are included in mock data for consistency across tests. - This change improves the accuracy of test data and aligns with the current data model requirements.
Summary by CodeRabbit
AuthenticatedUsertype to the GraphQL API, providing access to core user information including ID, name, email, profile image, and verification status.