import { GraphQLResolveInfo } from 'graphql' export type PromiseOrValue = Promise | T export function defined(value: T | null | undefined): value is T { return value !== null && value !== undefined } export function fail(msg: string): never { throw Error(msg) } export function failql(msg: string, info: GraphQLResolveInfo): never { throw Error(`${msg} (${info.parentType.name}.${info.fieldName})`) } export interface Lazy { (): T } export const lazy = (fn: () => T): Lazy => { let current = (): T => { const val = fn() current = () => val return val } return () => current() } export const unique = (...lists: T[][]) => Array.from(new Set(lists.flat())) export const valueIfOne = (list: T[]) => (list.length < 2 ? list[0] : list) // export function unique(array: T[]) { // return Array.from(new Set(array).values()) // }