Adds `select` which is used to specify the field projection for local and rest API calls. This is available as an optimization to reduce the payload's of requests and make the database queries more efficient. Includes: - [x] generate types for the `select` property - [x] infer the return type by `select` with 2 modes - include (`field: true`) and exclude (`field: false`) - [x] lots of integration tests, including deep fields / localization etc - [x] implement the property in db adapters - [x] implement the property in the local api for most operations - [x] implement the property in the rest api - [x] docs --------- Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
import { fileURLToPath } from 'node:url'
|
|
import path from 'path'
|
|
|
|
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
|
import { devUser } from '../credentials.js'
|
|
import { DeepPostsCollection } from './collections/DeepPosts/index.js'
|
|
import { LocalizedPostsCollection } from './collections/LocalizedPosts/index.js'
|
|
import { PostsCollection } from './collections/Posts/index.js'
|
|
import { VersionedPostsCollection } from './collections/VersionedPosts/index.js'
|
|
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
|
|
export default buildConfigWithDefaults({
|
|
// ...extend config here
|
|
collections: [
|
|
PostsCollection,
|
|
LocalizedPostsCollection,
|
|
VersionedPostsCollection,
|
|
DeepPostsCollection,
|
|
],
|
|
globals: [
|
|
{
|
|
slug: 'global-post',
|
|
fields: [
|
|
{
|
|
name: 'text',
|
|
type: 'text',
|
|
},
|
|
{
|
|
name: 'number',
|
|
type: 'number',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
admin: {
|
|
importMap: {
|
|
baseDir: path.resolve(dirname),
|
|
},
|
|
},
|
|
localization: {
|
|
locales: ['en', 'de'],
|
|
defaultLocale: 'en',
|
|
},
|
|
editor: lexicalEditor({
|
|
features: ({ defaultFeatures }) => [...defaultFeatures],
|
|
}),
|
|
cors: ['http://localhost:3000', 'http://localhost:3001'],
|
|
onInit: async (payload) => {
|
|
await payload.create({
|
|
collection: 'users',
|
|
data: {
|
|
email: devUser.email,
|
|
password: devUser.password,
|
|
},
|
|
})
|
|
|
|
// // Create image
|
|
// const imageFilePath = path.resolve(dirname, '../uploads/image.png')
|
|
// const imageFile = await getFileByPath(imageFilePath)
|
|
|
|
// await payload.create({
|
|
// collection: 'media',
|
|
// data: {},
|
|
// file: imageFile,
|
|
// })
|
|
},
|
|
typescript: {
|
|
outputFile: path.resolve(dirname, 'payload-types.ts'),
|
|
},
|
|
})
|