aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
506 stars 32 forks source link

[JS] Difficult to specify the result type on `Context` #315

Open dnys1 opened 1 year ago

dnys1 commented 1 year ago

When trying to type just the result of the backend request, you need to specify several irrelevant types which makes the resolver verbose and hard to grok at a glance. It's also very easy to forget which type parameter corresponds to what.

export function response(ctx: Context<never, never, never, never, HttpResponse>): string {
  // ...
}
dnys1 commented 1 year ago

One suggestion may be to split Context into RequestContext and ResponseContext with the relevant type args for each and make TResult the first parameter on ResponseContext since this is likely the most important type in the response method. E.g. it would be very nice if one could write:

export function response(ctx: ResponseContext<HttpResponse>): string {
  // ...
}