diff --git a/graph/mutators/asset.js b/graph/mutators/asset.js index 6524331e1..3d018658e 100644 --- a/graph/mutators/asset.js +++ b/graph/mutators/asset.js @@ -56,12 +56,25 @@ const closeNow = async (ctx, id) => } ); +/** + * scrapeAsset will force scrape an asset. + * + * @param {Object} ctx graphql context + * @param {String} id the asset's id to scrape + */ +const scrapeAsset = async (ctx, id) => { + const { services: { Scraper } } = ctx; + + return Scraper.create({ id }); +}; + module.exports = ctx => { let mutators = { Asset: { updateSettings: () => Promise.reject(errors.ErrNotAuthorized), updateStatus: () => Promise.reject(errors.ErrNotAuthorized), closeNow: () => Promise.reject(errors.ErrNotAuthorized), + scrape: () => Promise.reject(errors.ErrNotAuthorized), }, }; @@ -75,6 +88,7 @@ module.exports = ctx => { mutators.Asset.updateStatus = (id, status) => updateStatus(ctx, id, status); mutators.Asset.closeNow = id => closeNow(ctx, id); + mutators.Asset.scrape = id => scrapeAsset(ctx, id); } } diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index 8a638f589..e27d217fe 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -133,6 +133,9 @@ const RootMutation = { revokeToken: async (_, { input }, { mutators: { Token } }) => { await Token.revoke(input); }, + forceScrapeAsset: async (_, { id }, { mutators: { Asset } }) => { + await Asset.scrape(id); + }, }; module.exports = RootMutation; diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index f108a7ad4..2b62eaaf6 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -1395,6 +1395,12 @@ type SetUserRoleResponse implements Response { errors: [UserError!] } +type ForceScrapeAssetResponse implements Response { + + # An array of errors relating to the mutation that occurred. + errors: [UserError!] +} + # All mutations for the application are defined on this object. type RootMutation { @@ -1489,6 +1495,9 @@ type RootMutation { # Stop Ignoring comments by another user. stopIgnoringUser(id: ID!): StopIgnoringUserResponse + + # forceScrapeAsset will force scrape the Asset with the given ID. + forceScrapeAsset(id: ID!): ForceScrapeAssetResponse } type UsernameChangedPayload {