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

IN-4121 - async hooks / api client #7155

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

IN-4121 - async hooks / api client #7155

wants to merge 3 commits into from

Conversation

Olbix
Copy link
Contributor

@Olbix Olbix commented May 16, 2024

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSDoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

changeset-bot bot commented May 16, 2024

⚠️ No Changeset found

Latest commit: 1bc9c3b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

}

next();
getApiFunction(apiClientInstance, functionName, extensionName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick but I'd like to have async/await syntax in here as well (easier debugging imho), but you'd need to use this lib: https://www.npmjs.com/package/express-async-handler

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make onCreate async in packages/middleware/__tests__/integration/bootstrap/server.ts to validate async behaviour?

krystian wlodarski added 2 commits May 17, 2024 01:46
# Conflicts:
#	packages/middleware/src/apiClientFactory/index.ts
#	packages/middleware/src/handlers/prepareApiFunction/getApiFunction.ts
#	packages/middleware/src/handlers/prepareApiFunction/index.ts
Copy link
Collaborator

@WojtekTheWebDev WojtekTheWebDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, missing the integration tests to validate full scenario with extensions.

Comment on lines +6 to +7
): (req, res, next) => Promise<any> {
return async (req, res, next) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this hack in here ;p I'd go with https://www.npmjs.com/package/express-async-handler and avoid defining the return type, then express will validate if it returns what's expected.

Suggested change
): (req, res, next) => Promise<any> {
return async (req, res, next) => {
) {
return asyncHandler(async (req, res, next) => { ... });

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also try without the lib and without the Promise in return type

);
.reduce(async (configSoFar, extension) => {
const resolvedConfig = await configSoFar;
return extension.beforeCreate({ configuration: resolvedConfig });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await on lifecycles seems fine but I think you missed async behaviour on hooks like beforeCreate, afterCreate, beforeCall and afterCall

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.

None yet

2 participants