fix: threads draft arg through for child resolvers in GraphQL queries (#6196)
This commit is contained in:
@@ -352,6 +352,9 @@ export default buildConfigWithDefaults({
|
||||
relationTo: 'cyclical-relationship',
|
||||
},
|
||||
],
|
||||
versions: {
|
||||
drafts: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
graphQL: {
|
||||
|
||||
@@ -1001,6 +1001,79 @@ describe('collections-graphql', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should query correctly with draft argument', async () => {
|
||||
const publishValue = '1'
|
||||
const draftValue = '2'
|
||||
|
||||
// publish doc
|
||||
const newDoc = await payload.create({
|
||||
collection: 'cyclical-relationship',
|
||||
draft: false,
|
||||
data: {
|
||||
title: publishValue,
|
||||
},
|
||||
})
|
||||
|
||||
// create cyclical relationship
|
||||
await payload.update({
|
||||
collection: 'cyclical-relationship',
|
||||
id: newDoc.id,
|
||||
data: {
|
||||
relationToSelf: newDoc.id,
|
||||
},
|
||||
})
|
||||
|
||||
// save new version
|
||||
await payload.update({
|
||||
collection: 'cyclical-relationship',
|
||||
id: newDoc.id,
|
||||
draft: true,
|
||||
data: {
|
||||
title: draftValue,
|
||||
},
|
||||
})
|
||||
|
||||
const draftParentPublishedChild = `{
|
||||
CyclicalRelationships(draft: true) {
|
||||
docs {
|
||||
title
|
||||
relationToSelf(draft: false) {
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
const res1 = await restClient
|
||||
.GRAPHQL_POST({
|
||||
body: JSON.stringify({ query: draftParentPublishedChild }),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
|
||||
const queriedDoc = res1.data.CyclicalRelationships.docs[0]
|
||||
expect(queriedDoc.title).toEqual(draftValue)
|
||||
expect(queriedDoc.relationToSelf.title).toEqual(publishValue)
|
||||
|
||||
const publishedParentDraftChild = `{
|
||||
CyclicalRelationships(draft: false) {
|
||||
docs {
|
||||
title
|
||||
relationToSelf(draft: true) {
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
const res2 = await restClient
|
||||
.GRAPHQL_POST({
|
||||
body: JSON.stringify({ query: publishedParentDraftChild }),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
|
||||
const queriedDoc2 = res2.data.CyclicalRelationships.docs[0]
|
||||
expect(queriedDoc2.title).toEqual(publishValue)
|
||||
expect(queriedDoc2.relationToSelf.title).toEqual(draftValue)
|
||||
})
|
||||
|
||||
describe('Error Handler', () => {
|
||||
it('should return have an array of errors when making a bad request', async () => {
|
||||
const query = `query {
|
||||
|
||||
Reference in New Issue
Block a user