Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement deleteFile graphql mutation (#5292). #7937

Merged
merged 3 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ `
{
Expand Down
12 changes: 11 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,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 });
francois2metz marked this conversation as resolved.
Show resolved Hide resolved
if (file) {
const fileResult = await strapi.plugins.upload.services.upload.remove(file);
return { file: fileResult };
}
},
},
},
},
};
Expand Down
60 changes: 60 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,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,
},
});
});
});