fix(graphql): threads through correct draft value for upload relations (#6235)
This commit is contained in:
@@ -361,7 +361,7 @@ function buildObjectType({
|
||||
const locale = args.locale || context.req.locale
|
||||
const fallbackLocale = args.fallbackLocale || context.req.fallbackLocale
|
||||
let relatedCollectionSlug = field.relationTo
|
||||
const draft = args.draft ?? context.req.query?.draft
|
||||
const draft = Boolean(args.draft ?? context.req.query?.draft)
|
||||
|
||||
if (hasManyValues) {
|
||||
const results = []
|
||||
@@ -630,6 +630,7 @@ function buildObjectType({
|
||||
const locale = args.locale || context.req.locale
|
||||
const fallbackLocale = args.fallbackLocale || context.req.fallbackLocale
|
||||
const id = value
|
||||
const draft = Boolean(args.draft ?? context.req.query?.draft)
|
||||
|
||||
if (id) {
|
||||
const relatedDocument = await context.req.payloadDataLoader.load(
|
||||
@@ -638,7 +639,7 @@ function buildObjectType({
|
||||
currentDepth: 0,
|
||||
depth: 0,
|
||||
docID: id,
|
||||
draft: false,
|
||||
draft,
|
||||
fallbackLocale,
|
||||
locale,
|
||||
overrideAccess: false,
|
||||
|
||||
@@ -351,11 +351,27 @@ export default buildConfigWithDefaults({
|
||||
type: 'relationship',
|
||||
relationTo: 'cyclical-relationship',
|
||||
},
|
||||
{
|
||||
type: 'upload',
|
||||
name: 'media',
|
||||
relationTo: 'media',
|
||||
},
|
||||
],
|
||||
versions: {
|
||||
drafts: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
slug: 'media',
|
||||
access: openAccess,
|
||||
upload: true,
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
graphQL: {
|
||||
queries: (GraphQL) => {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import path from 'path'
|
||||
import { getFileByPath } from 'payload/uploads'
|
||||
import { mapAsync } from 'payload/utilities'
|
||||
|
||||
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||
@@ -1074,6 +1076,43 @@ describe('collections-graphql', () => {
|
||||
expect(queriedDoc2.relationToSelf.title).toEqual(draftValue)
|
||||
})
|
||||
|
||||
it('should query upload enabled docs', async () => {
|
||||
const file = await getFileByPath(path.resolve(__dirname, '../uploads/test-image.jpg'))
|
||||
|
||||
const mediaDoc = await payload.create({
|
||||
collection: 'media',
|
||||
file,
|
||||
data: {
|
||||
title: 'example',
|
||||
},
|
||||
})
|
||||
|
||||
// doc with upload relation
|
||||
const newDoc = await payload.create({
|
||||
collection: 'cyclical-relationship',
|
||||
data: {
|
||||
media: mediaDoc.id,
|
||||
},
|
||||
})
|
||||
|
||||
const query = `{
|
||||
CyclicalRelationship(id: ${typeof newDoc.id === 'number' ? newDoc.id : `"${newDoc.id}"`}) {
|
||||
media {
|
||||
id
|
||||
title
|
||||
}
|
||||
}
|
||||
}`
|
||||
const res = await restClient
|
||||
.GRAPHQL_POST({
|
||||
body: JSON.stringify({ query }),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
const queriedDoc = res.data.CyclicalRelationship
|
||||
expect(queriedDoc.media.id).toEqual(mediaDoc.id)
|
||||
expect(queriedDoc.media.title).toEqual('example')
|
||||
})
|
||||
|
||||
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