Created
September 20, 2020 16:06
-
-
Save jeswinsimon/4dcb22338fc1f112546c887cbd04238b to your computer and use it in GitHub Desktop.
Strapi delete uploaded media files using GraphQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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