페이로드 v4: forceSelect는 이제 select () 함수이며 미묘한 함정입니다

작성자

카테고리:

← 피드로
DEV Community · Kacper Zawojski · 2026-06-10 개발(SW)

Kacper Zawojski

In Payload v3, forceSelect was a static object that deep-merged with the caller’s select. In v4 it became a function — and that function replaces the caller’s select instead of adding to it:

export const Posts: CollectionConfig = {
  slug: 'posts',
  // Careful: you must spread the caller's select yourself, or you'll overwrite it!
  select: ({ operation, req, select }) =>
    select ? { ...select, title: true } : undefined,
  fields: [/* ... */],
}

Enter fullscreen mode Exit fullscreen mode

Returning undefined means “leave the caller’s select untouched.” You also get operation and req, so you can hand back a different select for the REST API than for the admin panel.

One important detail: there’s no document data here — select runs before read.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다