File tree Expand file tree Collapse file tree 3 files changed +58
-2
lines changed
packages/graphql/src/schema Expand file tree Collapse file tree 3 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -361,7 +361,7 @@ function buildObjectType({
361
361
const locale = args . locale || context . req . locale
362
362
const fallbackLocale = args . fallbackLocale || context . req . fallbackLocale
363
363
let relatedCollectionSlug = field . relationTo
364
- const draft = args . draft ?? context . req . query ?. draft
364
+ const draft = Boolean ( args . draft ?? context . req . query ?. draft )
365
365
366
366
if ( hasManyValues ) {
367
367
const results = [ ]
@@ -630,6 +630,7 @@ function buildObjectType({
630
630
const locale = args . locale || context . req . locale
631
631
const fallbackLocale = args . fallbackLocale || context . req . fallbackLocale
632
632
const id = value
633
+ const draft = Boolean ( args . draft ?? context . req . query ?. draft )
633
634
634
635
if ( id ) {
635
636
const relatedDocument = await context . req . payloadDataLoader . load (
@@ -638,7 +639,7 @@ function buildObjectType({
638
639
currentDepth : 0 ,
639
640
depth : 0 ,
640
641
docID : id ,
641
- draft : false ,
642
+ draft,
642
643
fallbackLocale,
643
644
locale,
644
645
overrideAccess : false ,
Original file line number Diff line number Diff line change @@ -351,11 +351,27 @@ export default buildConfigWithDefaults({
351
351
type : 'relationship' ,
352
352
relationTo : 'cyclical-relationship' ,
353
353
} ,
354
+ {
355
+ type : 'upload' ,
356
+ name : 'media' ,
357
+ relationTo : 'media' ,
358
+ } ,
354
359
] ,
355
360
versions : {
356
361
drafts : true ,
357
362
} ,
358
363
} ,
364
+ {
365
+ slug : 'media' ,
366
+ access : openAccess ,
367
+ upload : true ,
368
+ fields : [
369
+ {
370
+ name : 'title' ,
371
+ type : 'text' ,
372
+ } ,
373
+ ] ,
374
+ } ,
359
375
] ,
360
376
graphQL : {
361
377
queries : ( GraphQL ) => {
Original file line number Diff line number Diff line change 1
1
import type { Payload } from 'payload'
2
2
3
+ import path from 'path'
4
+ import { getFileByPath } from 'payload/uploads'
3
5
import { mapAsync } from 'payload/utilities'
4
6
5
7
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
@@ -1074,6 +1076,43 @@ describe('collections-graphql', () => {
1074
1076
expect ( queriedDoc2 . relationToSelf . title ) . toEqual ( draftValue )
1075
1077
} )
1076
1078
1079
+ it ( 'should query upload enabled docs' , async ( ) => {
1080
+ const file = await getFileByPath ( path . resolve ( __dirname , '../uploads/test-image.jpg' ) )
1081
+
1082
+ const mediaDoc = await payload . create ( {
1083
+ collection : 'media' ,
1084
+ file,
1085
+ data : {
1086
+ title : 'example' ,
1087
+ } ,
1088
+ } )
1089
+
1090
+ // doc with upload relation
1091
+ const newDoc = await payload . create ( {
1092
+ collection : 'cyclical-relationship' ,
1093
+ data : {
1094
+ media : mediaDoc . id ,
1095
+ } ,
1096
+ } )
1097
+
1098
+ const query = `{
1099
+ CyclicalRelationship(id: ${ typeof newDoc . id === 'number' ? newDoc . id : `"${ newDoc . id } "` } ) {
1100
+ media {
1101
+ id
1102
+ title
1103
+ }
1104
+ }
1105
+ }`
1106
+ const res = await restClient
1107
+ . GRAPHQL_POST ( {
1108
+ body : JSON . stringify ( { query } ) ,
1109
+ } )
1110
+ . then ( ( res ) => res . json ( ) )
1111
+ const queriedDoc = res . data . CyclicalRelationship
1112
+ expect ( queriedDoc . media . id ) . toEqual ( mediaDoc . id )
1113
+ expect ( queriedDoc . media . title ) . toEqual ( 'example' )
1114
+ } )
1115
+
1077
1116
describe ( 'Error Handler' , ( ) => {
1078
1117
it ( 'should return have an array of errors when making a bad request' , async ( ) => {
1079
1118
const query = `query {
You can’t perform that action at this time.
0 commit comments