moleculerjs/moleculer-apollo-server

Action specific ctx.call options

Closed this issue · 1 comments

This is an enhancement request.

I'd like a way to override ctx.call options for specific graphql handlers. Our services share a configuration and have a default timeout of 30 seconds. However we have a couple of mutation actions that may take longer. For example we have a data import mutation where users can upload spreadsheets that are parsed and then update the database. We have another mutation that if necessary provisions resources in Azure which can take a minute or two. For these specific actions I'd like to increase the timeout or add retries.

Similar to how we allow DataLoader options, I think something like this would work.

actions: {
  upload {
    visibility: 'public',
    graphql: {
      mutation: DataImportGql, 
      callOptions: { timeout: 120000, retries: 2 }
    },
    handler: (ctx) => {
      // do something
    }
  }
}

The properties in callOptions would be used as an options param in ctx.call

@shawnmcknight Showed me that you can override settings in the action definitions.

Only timeout is explicitly documented but it looks like the others will work as well. I tested the timeout setting and it solved my problem.

https://moleculer.services/docs/0.14/actions.html#Timeout