fix: #1887, dataloader rich text population infinite loop
This commit is contained in:
@@ -24,6 +24,42 @@ export default buildConfig({
|
||||
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'relation-a',
|
||||
labels: {
|
||||
singular: 'Relation A',
|
||||
plural: 'Relation As',
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'relationship',
|
||||
type: 'relationship',
|
||||
relationTo: 'relation-b',
|
||||
},
|
||||
{
|
||||
name: 'richText',
|
||||
type: 'richText',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'relation-b',
|
||||
labels: {
|
||||
singular: 'Relation B',
|
||||
plural: 'Relation Bs',
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'relationship',
|
||||
type: 'relationship',
|
||||
relationTo: 'relation-a',
|
||||
},
|
||||
{
|
||||
name: 'richText',
|
||||
type: 'richText',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
const user = await payload.create({
|
||||
|
||||
@@ -49,5 +49,88 @@ describe('dataloader', () => {
|
||||
const { docs } = response.Posts;
|
||||
expect(docs[0].title).toStrictEqual(postDoc.title);
|
||||
});
|
||||
|
||||
it('should avoid infinite loops', async () => {
|
||||
const relationA = await payload.create({
|
||||
collection: 'relation-a',
|
||||
data: {
|
||||
richText: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
text: 'relation a',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const relationB = await payload.create({
|
||||
collection: 'relation-b',
|
||||
data: {
|
||||
relationship: relationA.id,
|
||||
richText: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
text: 'relation b',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(relationA.id).toBeDefined();
|
||||
expect(relationB.id).toBeDefined();
|
||||
|
||||
await payload.update({
|
||||
collection: 'relation-a',
|
||||
id: relationA.id,
|
||||
data: {
|
||||
relationship: relationB.id,
|
||||
richText: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
text: 'relation a',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
children: [
|
||||
{
|
||||
text: '',
|
||||
},
|
||||
],
|
||||
type: 'relationship',
|
||||
value: {
|
||||
id: relationB.id,
|
||||
},
|
||||
relationTo: 'relation-b',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const relationANoDepth = await payload.findByID({
|
||||
collection: 'relation-a',
|
||||
id: relationA.id,
|
||||
depth: 0,
|
||||
});
|
||||
|
||||
expect(relationANoDepth.relationship).toStrictEqual(relationB.id);
|
||||
|
||||
const relationAWithDepth = await payload.findByID({
|
||||
collection: 'relation-a',
|
||||
id: relationA.id,
|
||||
depth: 4,
|
||||
});
|
||||
|
||||
const innerMostRelationship = relationAWithDepth.relationship.relationship.richText[1].value.relationship.relationship;
|
||||
|
||||
expect(typeof innerMostRelationship).toStrictEqual(relationB.id);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user