fix: cascade draft arg when querying globals with graphql

This commit is contained in:
Jarrod Flesch
2024-06-06 10:35:23 -04:00
parent 19f8cbcf76
commit 1b0afee70e
7 changed files with 146 additions and 20 deletions

View File

@@ -373,6 +373,29 @@ export default buildConfigWithDefaults({
],
},
],
globals: [
{
slug: 'global-1',
access: {
read: openAccess.read,
update: openAccess.update,
},
fields: [
{
type: 'text',
name: 'title',
},
{
name: 'relationship',
type: 'relationship',
relationTo: 'cyclical-relationship',
},
],
versions: {
drafts: true,
},
},
],
graphQL: {
queries: (GraphQL) => {
return {

View File

@@ -1117,6 +1117,63 @@ describe('collections-graphql', () => {
expect(queriedDoc.media.title).toEqual('example')
})
it('should cascade draft arg with globals', async () => {
// publish relationship doc
const newDoc = await payload.create({
collection: 'cyclical-relationship',
draft: false,
data: {
title: 'published relationship',
},
})
// save draft version relationship doc
await payload.update({
collection: 'cyclical-relationship',
id: newDoc.id,
draft: true,
data: {
title: 'draft relationship',
},
})
// update global (published data)
await payload.updateGlobal({
slug: 'global-1',
data: {
title: 'published title',
relationship: newDoc.id,
},
})
// update global (draft data)
await payload.updateGlobal({
slug: 'global-1',
draft: true,
data: {
title: 'draft title',
},
})
const query = `{
Global1(draft: true) {
title
relationship {
title
}
}
}`
const res1 = await restClient
.GRAPHQL_POST({
body: JSON.stringify({ query }),
})
.then((res) => res.json())
const queriedGlobal = res1.data.Global1
expect(queriedGlobal.title).toEqual('draft title')
expect(queriedGlobal.relationship.title).toEqual('draft relationship')
})
describe('Error Handler', () => {
it('should return have an array of errors when making a bad request', async () => {
const query = `query {