genql
genql copied to clipboard
Using genql for server side (resolver) typing
It looks like genql can be used for inserting proper types when writing the actual resolvers too, instead of just client side. However the support isn't great.
In an AWS amplify world I get types I can use as follows:
import { AppSyncResolverEvent } from "aws-lambda"
import { Maybe, MutationFooArgs, Foo } from "../generated/graphql"
export const foo = async (
event: AppSyncResolverEvent<MutationFooArgs>
): Promise<Maybe<Foo>> => {
...
}
With genql the best I could do was something like:
import { AppSyncResolverEvent } from "aws-lambda"
import { MutationGenqlSelection, Mutation } from "../generated/genql/schema"
export const foo = async (
event: AppSyncResolverEvent<MutationGenqlSelection["foo"]["__args"]["input"]>
): Promise<Mutation["foo"]> => {
...
}
This is harder to write and get correct as autocomplete doesn't work well here it seems.
Could genql create some types that would work better in the backend?
Genql is not built for this use case, it's better if you use the previous types generator for this