Files
payload/test/dataloader/config.ts
Patrik fb72d19d6c fix: graphql query concurrency issues (#6925)
## Description

This is the beta (v3) PR for the v2 PR
[here](https://github.com/payloadcms/payload/pull/6857)

Addresses #6800, #5108

- [x] I have read and understand the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## Checklist:

- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] Existing test suite passes locally with my changes
2024-07-08 15:55:04 +00:00

149 lines
3.1 KiB
TypeScript

import { fileURLToPath } from 'node:url'
import path from 'path'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
import { slateEditor } from '@payloadcms/richtext-slate'
import type { Post } from './payload-types.js'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js'
export default buildConfigWithDefaults({
collections: [
{
slug: 'posts',
fields: [
{
name: 'title',
type: 'text',
required: true,
},
{
name: 'owner',
type: 'relationship',
hooks: {
beforeChange: [({ req: { user } }) => user?.id],
},
relationTo: 'users',
},
],
},
{
slug: 'relation-a',
fields: [
{
name: 'relationship',
type: 'relationship',
relationTo: 'relation-b',
},
{
name: 'richText',
type: 'richText',
editor: slateEditor({}),
},
],
labels: {
plural: 'Relation As',
singular: 'Relation A',
},
},
{
slug: 'relation-b',
fields: [
{
name: 'relationship',
type: 'relationship',
relationTo: 'relation-a',
},
{
name: 'richText',
type: 'richText',
editor: slateEditor({}),
},
],
labels: {
plural: 'Relation Bs',
singular: 'Relation B',
},
},
{
fields: [
{
name: 'name',
type: 'text',
},
{
name: 'items',
type: 'relationship',
relationTo: 'items',
hasMany: true,
},
],
slug: 'shops',
access: { read: () => true },
},
{
fields: [
{
name: 'name',
type: 'text',
},
{
name: 'itemTags',
type: 'relationship',
relationTo: 'itemTags',
hasMany: true,
},
],
slug: 'items',
access: { read: () => true },
},
{
fields: [
{
name: 'name',
type: 'text',
},
],
slug: 'itemTags',
access: { read: () => true },
},
],
onInit: async (payload) => {
const user = await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
})
await payload.create({
collection: 'posts',
data: postDoc,
user,
})
const tag = await payload.create({
collection: 'itemTags',
data: { name: 'tag1' },
})
const item = await payload.create({
collection: 'items',
data: { name: 'item1', itemTags: [tag.id] },
})
const shop = await payload.create({
collection: 'shops',
data: { name: 'shop1', items: [item.id] },
})
},
typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts'),
},
})
export const postDoc: Pick<Post, 'title'> = {
title: 'test post',
}