-
Notifications
You must be signed in to change notification settings - Fork 173
Closed
Labels
bugSomething isn't workingSomething isn't workingcompletedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utility
Description
Expected Behavior
When using the @onPublish
and @onSubscribed
decorator of the AppSyncEventsResolver
the decorated methods should preserve the this
scope of the class they belong to.
This way, these methods can continue accessing class properties and methods.
Current Behavior
When applying the decorators the decorated method is no longer bound and this
goes to either the instance of AppSyncEventsResolver
or undefined
, thus preventing from using other class methods/properties.
Code snippet
const app = new AppSyncEventsResolver({ logger: console });
class Lambda {
public scope = 'scoped';
@app.onPublish('/foo')
public async handleFoo(payload: string) {
return `${this.scope} ${payload}`;
}
public async handler(event: unknown, context: Context) {
return this.stuff(event, context);
}
async stuff(event: unknown, context: Context) {
return app.resolve(event, context);
}
}
const lambda = new Lambda();
const handler = lambda.handler.bind(lambda);
Steps to Reproduce
N/A
Possible Solution
No response
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcompletedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utility
Type
Projects
Status
Shipped