Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: function configuration for auto transactions #1615

Merged
merged 2 commits into from
Oct 23, 2024
Merged

Conversation

tomfrew
Copy link
Contributor

@tomfrew tomfrew commented Sep 27, 2024

We currently wrap all mutation functions in a transaction which gets rolled back if the function throws an error. This is a great default but there are times where you do want to write to the db and also return an error. This PR adds optional configuration to our generated function wrappers which would enable users to control the behaviour of the functions runtime. And then uses this config to control the automatic transaction behaviour

e.g.

MyFunction.config = {
  autoTransaction: false,
};

export default MyFunction(async (ctx, inputs) => {
  // .. do things
});

or for hooks

const hooks: MyFunctionHooks = {
  beforeWrite: async (ctx, inputs, values, record) => {
   // ..do things
  },
};

MyFunction.config = {
  autoTransaction: false,
};

export default MyFunction(hooks);

@tomfrew tomfrew marked this pull request as ready for review September 27, 2024 11:42
packages/functions-runtime/src/index.d.ts Outdated Show resolved Hide resolved
packages/functions-runtime/src/tryExecuteFunction.js Outdated Show resolved Hide resolved
@davenewza davenewza marked this pull request as ready for review October 22, 2024 16:40
@davenewza davenewza merged commit 9ae1105 into main Oct 23, 2024
10 checks passed
@davenewza davenewza deleted the functionConfig branch October 23, 2024 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants