genql icon indicating copy to clipboard operation
genql copied to clipboard

Using genql for server side (resolver) typing

Open dnz-bdeboer opened this issue 2 years ago • 1 comments

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?

dnz-bdeboer avatar Jun 05 '23 07:06 dnz-bdeboer

Genql is not built for this use case, it's better if you use the previous types generator for this

remorses avatar Jun 05 '23 08:06 remorses