Hey
@311085554852823040
You want to see the source for where the endpoints are handled?
Basically all operations in payload are routed to one of these functions:
- Collections:
https://github.com/payloadcms/payload/tree/main/packages/payload/src/collections/operations- Globals:
https://github.com/payloadcms/payload/tree/main/packages/payload/src/globals/operations- Auth:
https://github.com/payloadcms/payload/tree/main/packages/payload/src/auth/operationsThe "basis" of the endpoints is handled by the next package:
https://github.com/payloadcms/payload/blob/main/packages/next/src/routes/index.tsThe actual routing is handled by a payload core utility:
https://github.com/payloadcms/payload/blob/main/packages/payload/src/utilities/handleEndpoints.ts#L62Let me know if you want more details on this, or what in particular you want more info on.
This was kind-of recently changed, as before most of this aside from the operations was handled by the
nextpackage.
Oeh thanks man!!
My pleasure
would this be a correct component diagram of payload and payload core?
Kind of yeah, the local api and the rest api use the same operations under the hood, it's just the routing that is slightly different
cool cool, but what i can't wrap my head around is
howactually data is send to the database for example, i have it now as a content manager, but basically that would be Nextjs/Payload core utility combined with the schema definition of collections to check?
All operations eventually get to a
dbcall. Take the
createoperation for example, it does some processing, calls some hooks, does some more processing, then it gets to this line:
https://github.com/payloadcms/payload/blob/main/packages/payload/src/collections/operations/create.ts#L269This is a call to the underlying db adapter directly. DB adapters, as the name suggests, use the adapter pattern to map these calls to actual db operations - in the case of
create, it calls the adapters own
createmethod. Let's say we are using
db-postgres, then at this point the data that we passed up to now gets transformed for writing (to better represent the actual columns we are writing), and then a special function called
upsertRowis called that updates or inserts this row in the actual database:
https://github.com/payloadcms/payload/blob/main/packages/drizzle/src/create.ts#L19How do we even get the
dbobject though? The
dbobject gets assigned to
payload(The
BasePayloadinstance) via initialization by using the config you passed with your chosen adapter, simple as that. Whenever you get a
payloadinstance, for example from a
req, we are always referring to the same cached
BasePayloadobject.
ah ah i see, let me work that out real quick!
would this be a better component representation?
It's better, in your case the Database Adapter will be mongoose (db-mongodb) but if you want something more representative of the actual flow then it would look a little more linear I think:
Admin ui -----
| |
| |
v |
API Handler |
| |
| |
v v
Core Operations / Local API
|
|
v
DB Adapter
...ah so the admin ui skips the api handler (like the local api goes straight to the database)
thanks btw for the time man, when i am finished i will be happy to share my project 🙂
Yes, at the end of the day the REST API basically just calls the same operations as the Local API
i know it is quite late (where i live) but i am confused still a bit. There is a Payload Core utility that handles requests received through the Nextjs endpoints. sort of.
But then there is also Node.js? How does this fit in everything?
Nodejs is a Javascript runtime environment, Next.js needs a runtime environment outside of the browser for certain processes, for example running an endpoint from the context of a server happens in Nodejs
copy that captain, my thanks
Star
Discord
online
Get dedicated engineering support directly from the Payload team.