fix(plugin-import-export): export with draft true (#11762)
### What? - GraphQL was broken because of an error with the enum for the drafts input which cannot be 'true'. - Selecting Draft was not doing anything as it wasn't being passed through to the find arguments. ### Why? This was causing any graphql calls to error. ### How? - Changed draft options to Yes/No instead of True/False - Correctly pass the drafts arg to `draft` Fixes #
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -54,6 +54,7 @@ export type SupportedTimezones =
|
||||
| 'Asia/Singapore'
|
||||
| 'Asia/Tokyo'
|
||||
| 'Asia/Seoul'
|
||||
| 'Australia/Brisbane'
|
||||
| 'Australia/Sydney'
|
||||
| 'Pacific/Guam'
|
||||
| 'Pacific/Noumea'
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user