-
Notifications
You must be signed in to change notification settings - Fork 175
style(event-handler): apply stricter linting #4578
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
Conversation
|
||
return this.#withErrorHandling( | ||
() => this.#executeSingleResolver(event, context, options), | ||
async () => await this.#executeSingleResolver(event, context, options), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just pass the unresolved promise here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, because as this is with this change, it slightly changes the behaviour from what it was.
type RouteHandler<TReturn = HandlerResponse> = ( | ||
reqCtx: RequestContext | ||
) => Promise<TReturn>; | ||
) => Promise<TReturn> | TReturn; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
|
||
return this.#withErrorHandling( | ||
() => this.#executeSingleResolver(event, context, options), | ||
async () => await this.#executeSingleResolver(event, context, options), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, because as this is with this change, it slightly changes the behaviour from what it was.
context: Context, | ||
options?: ResolveOptions | ||
): Promise<unknown> { | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function can still return a promise, the type signature should reflect that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are quite a few uses of unknown
in the AppSyncGraphQLResolver
. Do you have some suggestions on how we could we narrow down the return types for this?
}; | ||
|
||
type NextFunction = () => Promise<HandlerResponse | void>; | ||
type NextFunction = () => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried this change is going to encourage people not to await the next
function because they think it being async is optional. Failing to await next
causes the an error to be thrown and the whole requst fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got an idea (haven't tested it tho):
What if whenever someone calls app.use
we wrap their middleware arrow function in a function we control, before putting the wrapped middleware in the array.
Our function becomes the next
and doesn't care if it's called with await
or not, but it will always await
the function it's wrapping before returning its result.
This way (assuming I'm not just saying something dumb), it doesn't matter if customers forget to call await next
or even if the middleware is asynchronous or synchronous, we'll always treat it as async.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the issue is not with awaiting the middleware, it's the step after that, which is actually happening inside the the middlware handler. Not calling await
returns immediately and messes up the execution order. Even when I tested capturing the Promise and forcing an await inside the composeMiddleware
function, the problem was still there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok then - @sdangol I think this discussion is relevant to your question below.
Hi @sdangol - can you please address the feedback and get this merged in the next couple hrs? Thank you. |
Ah yeah, that test is a hangover from a bug where we used to accept |
…constructor any, added unknown to the return type of some functions in GraphQL resolver
) => Promise<HandlerResponse>; | ||
|
||
interface ErrorConstructor<T extends Error = Error> { | ||
// biome-ignore lint/suspicious/noExplicitAny: this is a generic type that is intentionally open |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@svozza @dreamorosi Can we narrow this down to something? I wasn't sure if we could
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the issue here is supporting custom error types, which can have arbitrary parameters when constructed:
class CustomError extends Error {
constructor(/* these parameters can be literally anything */) {
}
}
Not all issues are linked correctly. Please link each issue to the PR either manually or using a closing keyword in the format If mentioning more than one issue, separate them with commas: i.e. |
@svozza @dreamorosi For the use of void in unions, I wasn't able to find a way through it so I added an ignore for the lint rule. Narrowing the |
|
Summary
This PR resolves all the linting issues resulting from the new rules being introduced in #4545
Changes
async
from functions not doingawait
Issue number: closes #4575
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.