Skip to content

Instantly share code, notes, and snippets.

@tomitrescak
Created July 25, 2018 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomitrescak/068e89cc6702a146e3218b108c4aff21 to your computer and use it in GitHub Desktop.
Save tomitrescak/068e89cc6702a146e3218b108c4aff21 to your computer and use it in GitHub Desktop.
// 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