mirror of
https://github.com/wassname/talk.git
synced 2026-07-31 12:50:48 +08:00
Scrape Asset GraphQL Mutation
- Adds support for force scraping the asset via a GraphQL mutation.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user