diff --git a/packages/strapi-plugin-graphql/test/single-type.test.e2e.js b/packages/strapi-plugin-graphql/test/single-type.test.e2e.js index 5ed0d0d731..b219b45bec 100644 --- a/packages/strapi-plugin-graphql/test/single-type.test.e2e.js +++ b/packages/strapi-plugin-graphql/test/single-type.test.e2e.js @@ -58,7 +58,7 @@ describe('Single type Graphql support', () => { afterAll(() => modelsUtils.deleteContentType('home-page'), 60000); describe('Queries', () => { - test('No list avaialble', async () => { + test('No list available', async () => { const res = await graphqlQuery({ query: /* GraphQL */ ` { diff --git a/packages/strapi-plugin-upload/config/schema.graphql.js b/packages/strapi-plugin-upload/config/schema.graphql.js index 1d732f20e8..3d8794763e 100644 --- a/packages/strapi-plugin-upload/config/schema.graphql.js +++ b/packages/strapi-plugin-upload/config/schema.graphql.js @@ -24,7 +24,6 @@ module.exports = { Mutation: { createFile: false, updateFile: false, - deleteFile: false, upload: { description: 'Upload one file', resolverOf: 'plugins::upload.upload.upload', @@ -57,6 +56,17 @@ module.exports = { return await strapi.plugins.upload.services.upload.updateFileInfo(id, info); }, }, + deleteFile: { + description: 'Delete one file', + resolverOf: 'plugins::upload.upload.destroy', + resolver: async (obj, options, { context }) => { + const file = await strapi.plugins.upload.services.upload.fetch({ id: context.params.id }); + if (file) { + const fileResult = await strapi.plugins.upload.services.upload.remove(file); + return { file: fileResult }; + } + }, + }, }, }, }; diff --git a/packages/strapi-plugin-upload/test/graphqlUpload.test.e2e.js b/packages/strapi-plugin-upload/test/graphqlUpload.test.e2e.js index 32709115ec..3f3ad31147 100644 --- a/packages/strapi-plugin-upload/test/graphqlUpload.test.e2e.js +++ b/packages/strapi-plugin-upload/test/graphqlUpload.test.e2e.js @@ -147,4 +147,64 @@ describe('Upload plugin end to end tests', () => { }, }); }); + + test('Delete a file', async () => { + const res = await rq({ + url: '/graphql', + method: 'POST', + body: { + query: /* GraphQL */ ` + mutation removeFile($id: ID!) { + deleteFile(input: { where: { id: $id } }) { + file { + id + } + } + } + `, + variables: { + id: data.file.id, + }, + }, + }); + + expect(res.statusCode).toBe(200); + expect(res.body).toMatchObject({ + data: { + deleteFile: { + file: { + id: data.file.id, + }, + }, + }, + }); + }); + + test('Delete a file that dont exist', async () => { + const res = await rq({ + url: '/graphql', + method: 'POST', + body: { + query: /* GraphQL */ ` + mutation removeFile($id: ID!) { + deleteFile(input: { where: { id: $id } }) { + file { + id + } + } + } + `, + variables: { + id: '404', + }, + }, + }); + + expect(res.statusCode).toBe(200); + expect(res.body).toMatchObject({ + data: { + deleteFile: null, + }, + }); + }); });