diff --git a/packages/plugin-import-export/src/export/createExport.ts b/packages/plugin-import-export/src/export/createExport.ts index ff408eacb9..76021900a4 100644 --- a/packages/plugin-import-export/src/export/createExport.ts +++ b/packages/plugin-import-export/src/export/createExport.ts @@ -10,6 +10,7 @@ import { getSelect } from './getSelect.js' type Export = { collectionSlug: string + drafts?: 'no' | 'yes' exportsCollection: string fields?: string[] format: 'csv' | 'json' @@ -41,6 +42,7 @@ export const createExport = async (args: CreateExportArgs) => { id, name: nameArg, collectionSlug, + drafts, exportsCollection, fields, format, @@ -64,11 +66,12 @@ export const createExport = async (args: CreateExportArgs) => { const findArgs = { collection: collectionSlug, depth: 0, + draft: drafts === 'yes', limit: 100, locale, overrideAccess: false, page: 0, - select: fields ? getSelect(fields) : undefined, + select: Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined, sort, user, where, diff --git a/packages/plugin-import-export/src/export/getFields.ts b/packages/plugin-import-export/src/export/getFields.ts index e088957d26..adb36aab3b 100644 --- a/packages/plugin-import-export/src/export/getFields.ts +++ b/packages/plugin-import-export/src/export/getFields.ts @@ -97,16 +97,16 @@ export const getFields = (config: Config): Field[] => { }, width: '33%', }, - defaultValue: 'true', + defaultValue: 'yes', label: 'Drafts', options: [ { - label: 'True', - value: 'true', + label: 'Yes', + value: 'yes', }, { - label: 'False', - value: 'false', + label: 'No', + value: 'no', }, ], }, diff --git a/test/_community/payload-types.ts b/test/_community/payload-types.ts index eaa5dd9f23..4d2af3d499 100644 --- a/test/_community/payload-types.ts +++ b/test/_community/payload-types.ts @@ -54,6 +54,7 @@ export type SupportedTimezones = | 'Asia/Singapore' | 'Asia/Tokyo' | 'Asia/Seoul' + | 'Australia/Brisbane' | 'Australia/Sydney' | 'Pacific/Guam' | 'Pacific/Noumea' diff --git a/test/plugin-import-export/int.spec.ts b/test/plugin-import-export/int.spec.ts index 96de3363ee..6bf5f6f14d 100644 --- a/test/plugin-import-export/int.spec.ts +++ b/test/plugin-import-export/int.spec.ts @@ -3,12 +3,15 @@ import type { CollectionSlug, Payload } from 'payload' import path from 'path' import { fileURLToPath } from 'url' +import type { NextRESTClient } from '../helpers/NextRESTClient.js' + import { devUser } from '../credentials.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' import { readCSV, readJSON } from './helpers.js' import { richTextData } from './seed/richTextData.js' let payload: Payload +let restClient: NextRESTClient let user: any const filename = fileURLToPath(import.meta.url) @@ -16,7 +19,7 @@ const dirname = path.dirname(filename) describe('@payloadcms/plugin-import-export', () => { beforeAll(async () => { - ;({ payload } = (await initPayloadInt(dirname)) as { payload: Payload }) + ;({ payload, restClient } = await initPayloadInt(dirname)) user = await payload.login({ collection: 'users', data: { @@ -32,6 +35,25 @@ describe('@payloadcms/plugin-import-export', () => { } }) + describe('graphql', () => { + it('should not break graphql', async () => { + const query = `query { + __schema { + queryType { + name + } + } + }` + const response = await restClient + .GRAPHQL_POST({ + body: JSON.stringify({ query }), + }) + .then((res) => res.json()) + + expect(response.error).toBeUndefined() + }) + }) + describe('exports', () => { it('should create a file for collection csv from defined fields', async () => { let doc = await payload.create({ @@ -66,6 +88,53 @@ describe('@payloadcms/plugin-import-export', () => { expect(data[0].updatedAt).toBeDefined() }) + it('should create a file for collection csv with draft data', async () => { + const draftPage = await payload.create({ + collection: 'pages', + user, + data: { + title: 'Draft Page', + _status: 'published', + }, + }) + + await payload.update({ + collection: 'pages', + id: draftPage.id, + data: { + title: 'Draft Page Updated', + _status: 'draft', + }, + }) + + let doc = await payload.create({ + collection: 'exports', + user, + data: { + collectionSlug: 'pages', + fields: ['id', 'title', '_status'], + locale: 'en', + format: 'csv', + where: { + title: { contains: 'Draft ' }, + }, + }, + }) + + doc = await payload.findByID({ + collection: 'exports', + id: doc.id, + }) + + expect(doc.filename).toBeDefined() + const expectedPath = path.join(dirname, './uploads', doc.filename as string) + const data = await readCSV(expectedPath) + + expect(data[0].id).toBeDefined() + expect(data[0].title).toStrictEqual('Draft Page Updated') + expect(data[0]._status).toStrictEqual('draft') + }) + it('should create a file for collection csv from one locale', async () => { let doc = await payload.create({ collection: 'exports',