Skip to content

Instantly share code, notes, and snippets.

@tomitrescak
Created July 25, 2018 20:37
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/22f365cd72c4a6edf6450fb32d44f1ac to your computer and use it in GitHub Desktop.
Save tomitrescak/22f365cd72c4a6edf6450fb32d44f1ac to your computer and use it in GitHub Desktop.
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