Skip to content

Instantly share code, notes, and snippets.

View tomitrescak's full-sized avatar
🏠
Working from home

Tomas Trescak tomitrescak

🏠
Working from home
View GitHub Profile
// 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]>,
import { Query } from './utils';
export const query: Query = {
 // hit cmd+space here and hear "who let the dogs out!"
}
import * as Types from './types';
export type Resolver<T> = {
 [U in keyof Partial<typeof Types>]: {
 [P in keyof Partial<T>]: (parent: T, args: any, ctx: Context, info: GraphQLResolveInfo) => any
 }
};
export type Resolver<T, U = any> = {
 [index: string]: { // this is a problem
 [P in keyof Partial<T>]: (parent: T, args: U, ctx: Context, info: GraphQLResolveInfo) => any
 }
};
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]: (
export type Remapped<T> = {
 [P in keyof T]: (
 parent: null | undefined,
 args: FirstArgument<T[P]>,
 ctx: Context,
 info?: GraphQLResolveInfo
 ) => any
};
export type FirstArgument<T> = T extends (arg1: infer U, …args: any[]) => any ? U : any;
export interface Query {
notifications: <T = Notification[]>(args: { start?: Int, end?: Int }, info?: GraphQLResolveInfo | string, options?: Options) => Promise<T>
}
@tomitrescak
tomitrescak / result.ts
Last active July 25, 2018 20:46
Medium - Resolvers
// the types below do all the heavy lifting of making everything type safe
import { Mutation, Notification, Query, Resolver } from './utils';
export const query: Query = {
// hit cmd+space and feel the magic
// params and ctx are type safe, parent and info are 'any'
notifications(_parent, params, ctx, info) {
}
};
@tomitrescak
tomitrescak / Zed.cs
Last active June 6, 2018 05:03
ZED C# Example
using Emgu.CV.Structure;
using sl;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;