DefinitelyTyped/types/graphql-resolvers/index.d.ts
Alejandro Corredor 2482d17990 [@types/graphql-resolvers] Allow passing arbitrary TArgs to all utilities (#37227)
* Allow passing arbitrary TArgs to all utilities

I'm facing an issue when using `graphql-resolvers` along with `graphqlgen` (for generating resolver types: https://github.com/prisma/graphqlgen). I get correct generated types from `graphqlgen`, but when I try to create a resolver using `combineResolvers`, I get a type error.

Here is an example:
```js
contest: combineResolvers(authHelpers.isAuthenticated, contestResolver)
```

The snippet above gives me this typescript error:
```
Types of parameters 'args' and 'args' are incompatible.
    Property 'id' is missing in type 'TArgs' but required in type 'ArgsContest'.
```

Where my `contestResolver` has the type `(parent: undefined, args: QueryResolvers.ArgsContest, ctx: Context, info: GraphQLResolveInfo) => Contest | Promise<Contest>`.

Where `ArgsContests` is  
```
export interface ArgsContest {
    id: string;
}
```

And my `isAuthenticated` resolver has type `(parent: any, args: any, { me }: Context) => ForbiddenError | undefined`.

Since right now I have no way of passing my own `TArgs` I have no other way but to ignore the error.

With this PR I introduce the ability to pass a generic `TArgs` of my liking that let's me make typescript happy when using `graphqlgen` generated types. If no generic for that argument is passed, then `TArgsDefault` is used, which is equivalent to what the previous typings had.

* Add myself to the contributors list.

Forgot to add myself in the first commit.

* Fix contributors list

Made a mistake adding myself to the list.

* fixing contributors list

For some reason it did not like the multi-line version either.

* correct contributors

* fix linting errors, update graphql-tools

* format type definitions
2019-08-01 14:36:45 -07:00

35 lines
1.4 KiB
TypeScript

// Type definitions for graphql-resolvers 0.2
// Project: https://github.com/lucasconstantino/graphql-resolvers#readme
// Definitions by: Mike Engel <https://github.com/mike-engel>
// Alejandro Corredor <https://github.com/aecorredor>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
import { IFieldResolver } from "graphql-tools";
export const skip: undefined;
export interface TArgsDefault {
[argument: string]: any;
}
export function combineResolvers<TSource = any, TContext = any, TArgs = TArgsDefault>(
...resolvers: Array<IFieldResolver<TSource, TContext, TArgs>>
): IFieldResolver<TSource, TContext, TArgs>;
export function pipeResolvers<TSource = any, TContext = any, TArgs = TArgsDefault>(
...resolvers: Array<IFieldResolver<TSource, TContext, TArgs>>
): IFieldResolver<TSource, TContext, TArgs>;
export function allResolvers<TSource = any, TContext = any, TArgs = TArgsDefault>(
resolvers: Array<IFieldResolver<TSource, TContext, TArgs>>
): IFieldResolver<TSource, TContext, TArgs>;
export function resolveDependee(dependeeName: string): IFieldResolver<any, any, any>;
export function resolveDependees(dependeeNames: string[]): IFieldResolver<any, any, any>;
export function isDependee<TSource = any, TContext = any, TArgs = TArgsDefault>(
resolver: IFieldResolver<TSource, TContext, TArgs>
): IFieldResolver<TSource, TContext, TArgs>;