Skip to content

Using genql for server side (resolver) typing #128

@dnz-bdeboer

Description

@dnz-bdeboer

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions