Skip to content

Commit 47601bd

Browse files
committed
feat(generic): add generic type def
1 parent e2cfb0f commit 47601bd

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

examples/authentication/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const helloMiddleware = chain([
5151

5252
const resolvers: IResolvers = {
5353
Query: {
54-
hello: helloMiddleware((_, { name }) => `Hello ${name || "World"}`)
54+
hello: helloMiddleware<any, { name: string }>(
55+
(_, { name }) => `Hello ${name || "World"}`
56+
)
5557
}
5658
};
5759

src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export type Resolver = (parent: any, args: any, context: any, info: any) => any;
2-
31
export type Next = () => any;
42

53
export type MiddlewareResolver = (
@@ -10,8 +8,13 @@ export type MiddlewareResolver = (
108
info: any
119
) => any;
1210

13-
export const chain = (middlewares: MiddlewareResolver[]) => (
14-
resolver: Resolver
11+
export const chain = (middlewares: MiddlewareResolver[]) => <
12+
Parent = any,
13+
Args = any,
14+
Context = any,
15+
Info = any
16+
>(
17+
resolver: (parent: Parent, args: Args, context: Context, info: Info) => any
1518
) => (parent: any, args: any, context: any, info: any) => {
1619
const newMiddlewares = [...middlewares];
1720
const next: Next = () => {

0 commit comments

Comments
 (0)