Created
July 25, 2018 20:40
-
-
Save tomitrescak/068e89cc6702a146e3218b108c4aff21 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// file: utils.ts | |
import { GraphQLResolveInfo } from 'graphql'; | |
import { Mutation as ApiMutation, Query as ApiQuery } from './generated/api'; | |
import { Prisma } from './generated/prisma'; | |
import * as Types from './types; // you can omit this | |
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 | |
}; | |
export interface Context { | |
db: Prisma; | |
} | |
export type Query = Partial<Remapped<ApiQuery>>; | |
export type Mutation = Partial<Remapped<ApiMutation>>; | |
export type Resolver<T> = { | |
[U in keyof Partial<typeof Types>]: { // or [index: string]: { | |
[P in keyof Partial<T>]: (parent: T, args: any, ctx: Context, info: GraphQLResolveInfo) => any | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment