Skip to content

Commit

Permalink
Implement deleteFile graphql mutation (strapi#5292).
Browse files Browse the repository at this point in the history
Signed-off-by: Fran莽ois de Metz <francois@2metz.fr>
  • Loading branch information
francois2metz committed Sep 29, 2020
1 parent c527595 commit a9153cb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/strapi-plugin-upload/config/schema.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = {
Mutation: {
createFile: false,
updateFile: false,
deleteFile: false,
upload: {
description: 'Upload one file',
resolverOf: 'plugins::upload.upload.upload',
Expand Down Expand Up @@ -57,6 +56,15 @@ 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 });
const fileResult = await strapi.plugins.upload.services.upload.remove(file);
return { file: fileResult };
},
},
},
},
};
Expand Down
32 changes: 32 additions & 0 deletions packages/strapi-plugin-upload/test/graphqlUpload.test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,36 @@ 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,
},
},
},
});
});
});

0 comments on commit a9153cb

Please sign in to comment.