-
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
Changes from 3 commits
bc527d3
3b89362
7311816
e3759c5
2c2ef47
6ae3368
167c4ec
bf576e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,11 +152,7 @@ class AppSyncGraphQLResolver extends Router { | |
* @param context - The AWS Lambda context object. | ||
* @param options - Optional parameters for the resolver, such as the scope of the handler. | ||
*/ | ||
public async resolve( | ||
event: unknown, | ||
context: Context, | ||
options?: ResolveOptions | ||
): Promise<unknown> { | ||
public resolve(event: unknown, context: Context, options?: ResolveOptions) { | ||
if (Array.isArray(event)) { | ||
if (event.some((e) => !isAppSyncGraphQLEvent(e))) { | ||
this.logger.warn( | ||
|
@@ -178,7 +174,7 @@ class AppSyncGraphQLResolver extends Router { | |
} | ||
|
||
return this.#withErrorHandling( | ||
() => this.#executeSingleResolver(event, context, options), | ||
async () => await this.#executeSingleResolver(event, context, options), | ||
event, | ||
options | ||
); | ||
|
@@ -197,7 +193,7 @@ class AppSyncGraphQLResolver extends Router { | |
fn: () => Promise<unknown>, | ||
event: AppSyncResolverEvent<Record<string, unknown>>, | ||
options?: ResolveOptions | ||
): Promise<unknown> { | ||
) { | ||
try { | ||
return await fn(); | ||
} catch (error) { | ||
|
@@ -377,11 +373,11 @@ class AppSyncGraphQLResolver extends Router { | |
* @param options - Optional parameters for the resolver, such as the scope of the handler. | ||
* @throws {ResolverNotFoundException} If no resolver is registered for the given field and type. | ||
*/ | ||
async #executeSingleResolver( | ||
#executeSingleResolver( | ||
event: AppSyncResolverEvent<Record<string, unknown>>, | ||
context: Context, | ||
options?: ResolveOptions | ||
): Promise<unknown> { | ||
) { | ||
|
||
const { fieldName, parentTypeName: typeName } = event.info; | ||
|
||
const resolverHandlerOptions = this.resolverRegistry.resolve( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ type ErrorHandler<T extends Error = Error> = ( | |
) => Promise<HandlerResponse>; | ||
|
||
interface ErrorConstructor<T extends Error = Error> { | ||
new (...args: any[]): T; | ||
new (...args: unknown[]): T; | ||
prototype: T; | ||
} | ||
|
||
|
@@ -57,7 +57,7 @@ type HandlerResponse = Response | JSONObject; | |
|
||
type RouteHandler<TReturn = HandlerResponse> = ( | ||
reqCtx: RequestContext | ||
) => Promise<TReturn>; | ||
) => Promise<TReturn> | TReturn; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
|
||
type HttpMethod = keyof typeof HttpVerbs; | ||
|
||
|
@@ -78,12 +78,16 @@ type RestRouteOptions = { | |
middleware?: Middleware[]; | ||
}; | ||
|
||
type NextFunction = () => Promise<HandlerResponse | void>; | ||
type NextFunction = () => | ||
|
||
| Promise<void> | ||
| Promise<HandlerResponse> | ||
| HandlerResponse | ||
| void; | ||
|
||
type Middleware = (args: { | ||
reqCtx: RequestContext; | ||
next: NextFunction; | ||
}) => Promise<void | HandlerResponse>; | ||
}) => Promise<void> | Promise<HandlerResponse> | HandlerResponse | void; | ||
|
||
type RouteRegistryOptions = { | ||
/** | ||
|
@@ -176,4 +180,5 @@ export type { | |
RouteRegistryOptions, | ||
ValidationResult, | ||
CompressionOptions, | ||
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.
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.