Skip to content

Bug: AppSyncEventsResolver decorators break scope #3973

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

Open
dreamorosi opened this issue May 24, 2025 · 0 comments · May be fixed by #3974
Open

Bug: AppSyncEventsResolver decorators break scope #3973

dreamorosi opened this issue May 24, 2025 · 0 comments · May be fixed by #3974
Assignees
Labels
bug Something isn't working confirmed The scope is clear, ready for implementation event-handler This item relates to the Event Handler Utility

Comments

@dreamorosi
Copy link
Contributor

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

@dreamorosi dreamorosi self-assigned this May 24, 2025
@dreamorosi dreamorosi added bug Something isn't working confirmed The scope is clear, ready for implementation event-handler This item relates to the Event Handler Utility labels May 24, 2025
@dreamorosi dreamorosi moved this from Triage to Pending review in Powertools for AWS Lambda (TypeScript) May 24, 2025
@dreamorosi dreamorosi changed the title Bug: TITLE Bug: AppSyncEventsResolver decorators break scope May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed The scope is clear, ready for implementation event-handler This item relates to the Event Handler Utility
Projects
Status: Pending review
1 participant