-
-
Notifications
You must be signed in to change notification settings - Fork 796
Description
Steps to reproduce
As long as feathers dove should behave like feathers crow, it is currently not possible to create a new context object which will returned and reused in the following hooks.
If I create a new context object with spread operators during the hook, changing some query parameters and returning this context at the end of the hook. It will be used in the following hooks in feathers v4, in feathers v5 the original context from the function parameter will be reused in the next hooks and not the object what was return by the previous hooks. That means the return object isn't available in the following workflow (service and hooks).
Example:
const worksInV4AndV5 = (context) => {
context.params.query.foo = 'worksInV4AndV5';
return context;
};
const worksInV4NotInV5 = (context) => {
return {
...context,
params: {
...context.params,
query: {
...context.params.query,
foo: 'worksInV4NotInV5'
}
}
};
};
const logHook = (context) => {
// logs in v4 'worksInV4NotInV5'
// logs in v5 'worksInV4AndV5'
console.log(context.params.query.foo);
};
const hooks = {
before: {
all: [],
get: [
worksInV4AndV5,
worksInV4NotInV5,
logHook
],
find: [
worksInV4AndV5,
worksInV4NotInV5,
logHook
],
create: [],
update: [],
patch: [],
remove: [],
},
after: {
all: [],
get: [],
find: [],
create: [],
update: [],
patch: [],
remove: [],
},
error: {
all: [],
get: [],
find: [],
create: [],
update: [],
patch: [],
remove: [],
}
};
...
service.hooks(hooks);If I run the application and making a get on the service, it will log in v4 'worksInV4NotInV5' and in version 5 'worksInV4AndV5'.
Expected behaviour
The returned context should be used in the following hooks, like in version 4 of feathers.
Actual behaviour
Currently, in version 5 it doesn't matter if we will return a new context object, the current or undefined. The original context object will be used in the following hooks. That means if we don't manipulate the original object, those changes aren't available in the following hooks.
System configuration
Module versions (especially the part that's not working):
feathers dove (Version 5 pre.9 and pre.10)
NodeJS version:
Version v12.22.6, v14.17.6 and v16.9.1
Operating System:
macOS Catalina Version 10.15.7