Last active
May 5, 2018 23:01
-
-
Save devuxer/bed6197f16fbf1fd94d008f423a409e4 to your computer and use it in GitHub Desktop.
graphile-build typings file proposal
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
// todo verify TypeScript's `[key: string]: any` is equivalent to flow's `[string]: mixed` | |
// todo verify TypeScript's Build & BuildExtensions is equivalent to flow's build: { ...Build, ...BuildExtensions } | |
declare module "graphile-build" { | |
import { GraphQLInterfaceType } from "graphql"; | |
import { EventEmitter } from "events"; | |
import { GraphQLResolveInfo, GraphQLType, GraphQLNamedType, GraphQLSchema } from "graphql"; | |
type TriggerChangeType = () => void; | |
export type WatchUnwatch = (triggerChange: TriggerChangeType) => void; | |
export type Options = { | |
[key: string]: any; | |
}; | |
export type Scope = { | |
[key: string]: any; | |
}; | |
export type Context = { | |
scope: Scope; | |
type: string; | |
[key: string]: any; | |
}; | |
type SupportedHookTypes = {} | Build | Array<GraphQLInterfaceType>; | |
export type Hook<Type extends SupportedHookTypes, BuildExtensions extends any, ContextExtensions extends any> = ( | |
input: Type, | |
build: Build & BuildExtensions, | |
context: Context & ContextExtensions | |
) => Type; | |
export type Plugin = (builder: SchemaBuilder, options: Options) => Promise<void> | void; | |
export type FieldsByTypeName = { | |
[key: string]: { | |
[key: string]: ResolveTree; | |
}; | |
}; | |
export type ResolveTree = { | |
name: string; | |
alias: string; | |
args: { | |
[key: string]: any; | |
}; | |
fieldsByTypeName: FieldsByTypeName; | |
}; | |
export type parseResolveInfo = ( | |
resolveInfo: GraphQLResolveInfo, | |
options?: { keepRoot?: boolean; deep?: boolean } | |
) => ResolveTree | FieldsByTypeName | null | void; | |
export type simplifyParsedResolveInfoFragmentWithType = ( | |
parsedResolveInfoFragment: ResolveTree, | |
Type: GraphQLType | |
) => ResolveTree & { fields: {} }; | |
export type getAliasFromResolveInfo = (resolveInfo: GraphQLResolveInfo) => string; | |
// todo using any instead of * in several places here but is there a better choice? | |
export type Build = { | |
graphileBuildVersion: string; | |
graphql: any; | |
parseResolveInfo: parseResolveInfo; | |
simplifyParsedResolveInfoFragmentWithType: simplifyParsedResolveInfoFragmentWithType; | |
getAliasFromResolveInfo: getAliasFromResolveInfo; | |
resolveAlias(data: {}, _args: any, _context: any, resolveInfo: GraphQLResolveInfo): string; | |
addType: (type: GraphQLNamedType) => void; | |
getTypeByName: (typeName: string) => GraphQLType; | |
extend: <Obj1, Obj2>(base: Obj1, extra: Obj2, hint?: string) => Obj1 & Obj2; | |
newWithHooks: /* todo verify this type */ <T extends GraphQLNamedType | GraphQLSchema>( | |
ctor: { new (): T }, | |
spec: {}, | |
scope: {}, | |
returnNullOnInvalid?: boolean | |
) => T | undefined; | |
fieldDataGeneratorsByType: Map<any, any>; // @deprecated - use fieldDataGeneratorsByFieldNameByType instead | |
fieldDataGeneratorsByFieldNameByType: Map<any, any>; | |
fieldArgDataGeneratorsByFieldNameByType: Map<any, any>; | |
inflection: { | |
[key: string]: (...args: Array<any>) => string; | |
}; | |
}; | |
export interface SchemaBuilder extends EventEmitter { | |
watchers: Array<WatchUnwatch>; | |
unwatchers: Array<WatchUnwatch>; | |
triggerChange?: TriggerChangeType; | |
depth: number; | |
hooks: { | |
[key: string]: Array<Hook<any, any, any>>; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment