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 = {
|
type Export = {
|
||||||
collectionSlug: string
|
collectionSlug: string
|
||||||
|
drafts?: 'no' | 'yes'
|
||||||
exportsCollection: string
|
exportsCollection: string
|
||||||
fields?: string[]
|
fields?: string[]
|
||||||
format: 'csv' | 'json'
|
format: 'csv' | 'json'
|
||||||
@@ -41,6 +42,7 @@ export const createExport = async (args: CreateExportArgs) => {
|
|||||||
id,
|
id,
|
||||||
name: nameArg,
|
name: nameArg,
|
||||||
collectionSlug,
|
collectionSlug,
|
||||||
|
drafts,
|
||||||
exportsCollection,
|
exportsCollection,
|
||||||
fields,
|
fields,
|
||||||
format,
|
format,
|
||||||
@@ -64,11 +66,12 @@ export const createExport = async (args: CreateExportArgs) => {
|
|||||||
const findArgs = {
|
const findArgs = {
|
||||||
collection: collectionSlug,
|
collection: collectionSlug,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
|
draft: drafts === 'yes',
|
||||||
limit: 100,
|
limit: 100,
|
||||||
locale,
|
locale,
|
||||||
overrideAccess: false,
|
overrideAccess: false,
|
||||||
page: 0,
|
page: 0,
|
||||||
select: fields ? getSelect(fields) : undefined,
|
select: Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined,
|
||||||
sort,
|
sort,
|
||||||
user,
|
user,
|
||||||
where,
|
where,
|
||||||
|
|||||||
@@ -97,16 +97,16 @@ export const getFields = (config: Config): Field[] => {
|
|||||||
},
|
},
|
||||||
width: '33%',
|
width: '33%',
|
||||||
},
|
},
|
||||||
defaultValue: 'true',
|
defaultValue: 'yes',
|
||||||
label: 'Drafts',
|
label: 'Drafts',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
label: 'True',
|
label: 'Yes',
|
||||||
value: 'true',
|
value: 'yes',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'False',
|
label: 'No',
|
||||||
value: 'false',
|
value: 'no',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export type SupportedTimezones =
|
|||||||
| 'Asia/Singapore'
|
| 'Asia/Singapore'
|
||||||
| 'Asia/Tokyo'
|
| 'Asia/Tokyo'
|
||||||
| 'Asia/Seoul'
|
| 'Asia/Seoul'
|
||||||
|
| 'Australia/Brisbane'
|
||||||
| 'Australia/Sydney'
|
| 'Australia/Sydney'
|
||||||
| 'Pacific/Guam'
|
| 'Pacific/Guam'
|
||||||
| 'Pacific/Noumea'
|
| 'Pacific/Noumea'
|
||||||
|
|||||||
@@ -3,12 +3,15 @@ import type { CollectionSlug, Payload } from 'payload'
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
|
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||||
|
|
||||||
import { devUser } from '../credentials.js'
|
import { devUser } from '../credentials.js'
|
||||||
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
||||||
import { readCSV, readJSON } from './helpers.js'
|
import { readCSV, readJSON } from './helpers.js'
|
||||||
import { richTextData } from './seed/richTextData.js'
|
import { richTextData } from './seed/richTextData.js'
|
||||||
|
|
||||||
let payload: Payload
|
let payload: Payload
|
||||||
|
let restClient: NextRESTClient
|
||||||
let user: any
|
let user: any
|
||||||
|
|
||||||
const filename = fileURLToPath(import.meta.url)
|
const filename = fileURLToPath(import.meta.url)
|
||||||
@@ -16,7 +19,7 @@ const dirname = path.dirname(filename)
|
|||||||
|
|
||||||
describe('@payloadcms/plugin-import-export', () => {
|
describe('@payloadcms/plugin-import-export', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
;({ payload } = (await initPayloadInt(dirname)) as { payload: Payload })
|
;({ payload, restClient } = await initPayloadInt(dirname))
|
||||||
user = await payload.login({
|
user = await payload.login({
|
||||||
collection: 'users',
|
collection: 'users',
|
||||||
data: {
|
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', () => {
|
describe('exports', () => {
|
||||||
it('should create a file for collection csv from defined fields', async () => {
|
it('should create a file for collection csv from defined fields', async () => {
|
||||||
let doc = await payload.create({
|
let doc = await payload.create({
|
||||||
@@ -66,6 +88,53 @@ describe('@payloadcms/plugin-import-export', () => {
|
|||||||
expect(data[0].updatedAt).toBeDefined()
|
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 () => {
|
it('should create a file for collection csv from one locale', async () => {
|
||||||
let doc = await payload.create({
|
let doc = await payload.create({
|
||||||
collection: 'exports',
|
collection: 'exports',
|
||||||
|
|||||||
Reference in New Issue
Block a user