Created
July 25, 2018 20:37
-
-
Save tomitrescak/22f365cd72c4a6edf6450fb32d44f1ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GraphQLResolveInfo } from 'graphql'; | |
import { Mutation as ApiMutation, Query as ApiQuery } from './generated/api'; | |
import { Prisma } from './generated/prisma'; | |
export interface Context { | |
db: Prisma; | |
request: any; | |
} | |
export type FirstArgument<T> = T extends (arg1: infer U, …args: any[]) => any ? U : any; | |
export type Remapped<T> = { | |
[P in keyof T]: ( | |
parent: null | undefined, | |
args: FirstArgument<T[P]>, | |
ctx: Context, | |
info?: GraphQLResolveInfo | |
) => any | |
}; | |
// Following will make all your query and mutation resolvers type safe | |
export type Query = Partial<Remapped<ApiQuery>>; | |
export type Mutation = Partial<Remapped<ApiMutation>>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment