fix(payload): #6800, #5108 - graphql query concurrency issues (#6857)

Fixes #6800 and #5108 by improving the `isolateObjectProperty` utility
function and flattening `req.transactionID` and
`req.transactionIDPromise` to a single `req.transactionID` property.
This commit is contained in:
James Mikrut
2024-06-25 14:57:50 -04:00
committed by GitHub
parent 874774375f
commit bb911cc7ec
44 changed files with 191 additions and 75 deletions

View File

@@ -57,6 +57,48 @@ export default buildConfigWithDefaults({
},
],
},
{
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({
@@ -72,6 +114,19 @@ export default buildConfigWithDefaults({
collection: 'posts',
data: postDoc,
})
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] },
})
},
})

View File

@@ -31,6 +31,35 @@ describe('dataloader', () => {
if (loginResult.token) token = loginResult.token
})
it('should allow multiple parallel queries', async () => {
for (let i = 0; i < 100; i++) {
const query = `
query {
Shops {
docs {
name
items {
name
}
}
}
Items {
docs {
name
itemTags {
name
}
}
}
}`
const response = await client.request(query)
expect(response).toStrictEqual({
Shops: { docs: [{ name: 'shop1', items: [{ name: 'item1' }] }] },
Items: { docs: [{ name: 'item1', itemTags: [{ name: 'tag1' }] }] },
})
}
})
it('should allow querying via graphql', async () => {
const query = `query {
Posts {