Using getPayload in a Separate Next.js Project with Full Type Safety in NX Monorepo #12534
Unanswered
BetterLuke
asked this question in
Q&A
Replies: 1 comment
-
Not really familiar with the NX, but there is a sample repo for Turborepo. Hopefully it helps https://github.com/fusionary/turbo-payload |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi PayloadCMS community,
I'm working on an NX monorepo with two projects:
app-backend
(a PayloadCMS instance) andapp-frontend
(a Next.js app). I wantapp-frontend
to usegetPayload
to create a fully typed Payload instance for direct database access (Local API), ensuring type hints for thecollection
field (e.g.,'banner' | 'users' | 'media'
) and query results (e.g.,Banner[]
), while avoiding dependencies likesharp
. Here's my setup and issue.Setup
Monorepo Structure
app-backend
ConfigurationIssue
When importing
app-backend
's config intoapp-frontend
and usinggetPayload
, thecollection
field inpayload.find
lacks type hints (typed asstring
instead of'banner' | 'users' | 'media'
):Proposed Solution
To achieve type safety, I created a minimal
payload.config.ts
inapp-frontend
, reusingapp-backend
's collections:Dependencies
Type Sync
Questions
payload.config.ts
inapp-frontend
the best approach to ensure type safety forcollection
and query results while avoiding dependencies likesharp
?app-backend
's config withgetPayload
and retain type hints without a local config? If so, how?This solution works, but I’d love feedback on optimizing type safety or configuration sharing in NX. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions