Skip to content

Instantly share code, notes, and snippets.

@jeswinsimon
Created September 20, 2020 16:06
Show Gist options
  • Save jeswinsimon/4dcb22338fc1f112546c887cbd04238b to your computer and use it in GitHub Desktop.
Save jeswinsimon/4dcb22338fc1f112546c887cbd04238b to your computer and use it in GitHub Desktop.
Strapi delete uploaded media files using GraphQL
/**
* GraphQL resolver for deleting uploaded media in Strapi
* extensions/upload/config/schema.graphql.js
*/
module.exports = {
resolver: {
Mutation: {
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 };
},
},
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment