mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
[@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
This commit is contained in:
committed by
Jesse Trinity
parent
825b12a4c4
commit
2482d17990
Vendored
+9
-12
@@ -1,37 +1,34 @@
|
||||
// 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: 2.6
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
import { IFieldResolver } from "graphql-tools";
|
||||
|
||||
export const skip: undefined;
|
||||
|
||||
export interface TArgs {
|
||||
export interface TArgsDefault {
|
||||
[argument: string]: any;
|
||||
}
|
||||
|
||||
export function combineResolvers<TSource = any, TContext = 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>(
|
||||
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>(
|
||||
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, TArgs>;
|
||||
export function resolveDependee(dependeeName: string): IFieldResolver<any, any, any>;
|
||||
|
||||
export function resolveDependees(
|
||||
dependeeNames: string[]
|
||||
): IFieldResolver<any, any, TArgs>;
|
||||
export function resolveDependees(dependeeNames: string[]): IFieldResolver<any, any, any>;
|
||||
|
||||
export function isDependee<TSource = any, TContext = any>(
|
||||
export function isDependee<TSource = any, TContext = any, TArgs = TArgsDefault>(
|
||||
resolver: IFieldResolver<TSource, TContext, TArgs>
|
||||
): IFieldResolver<TSource, TContext, TArgs>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"graphql-tools": "^4.0.2"
|
||||
"graphql-tools": "^4.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user