Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFieldResolver args should allow typing #583

Closed
thevtm opened this issue Jan 17, 2018 · 2 comments
Closed

IFieldResolver args should allow typing #583

thevtm opened this issue Jan 17, 2018 · 2 comments

Comments

@thevtm
Copy link

thevtm commented Jan 17, 2018

I've been using Apollo's GraphQL solutions for a while and I find them amazing, really good work. 👍
So I was updating some dependencies in a project and I got this type error that wasn't occurring before the update. 🐛

Expected Behavior

import { IResolvers } from "graphql-tools/dist/Interfaces";

interface IGQLUser {
  id: string;
  name: string;
}

interface IUserResolverArgs {
  id: string;
}

export async function userResolver(obj: any, args: IUserResolverArgs): Promise<IGQLUser | null> {
  return { id: args.id, name: "Frank" };
}

const resolver: IResolvers = {
  Query: {
    user: userResolver,
  },
};

This code to not error.

Actual Behavior

Error

TS2322: Type '{ Query: { user: (obj: any, args: IUserResolverArgs) => Promise<IGQLUser | null>; }; }' is not assignable to type 'IResolvers'.
Property 'Query' is incompatible with index signature.
  Type '{ user: (obj: any, args: IUserResolverArgs) => Promise<IGQLUser | null>; }' is not assignable to type '(() => any) | IResolverObject | GraphQLScalarType'.
    Type '{ user: (obj: any, args: IUserResolverArgs) => Promise<IGQLUser | null>; }' is not assignable to type 'GraphQLScalarType'.
      Property 'name' is missing in type '{ user: (obj: any, args: IUserResolverArgs) => Promise<IGQLUser | null>; }'.

Specifications

  • Version: 1.1.0

Suggested solution

Use the graphql-js implementation like in the previous versions.

export type GraphQLFieldResolver<
  TSource,
  TContext,
  TArgs = { [argument: string]: any },
> = (
  source: TSource,
  args: TArgs,
  context: TContext,
  info: GraphQLResolveInfo,
) => mixed;
@corydeppen
Copy link
Contributor

I continue to run into this as well. Turning strictFunctionTypes off gets rid of the error, but it's clearly a hack. This seems related to DefinitelyTyped/DefinitelyTyped#21359, which I still feel is unresolved. If TS can't be used with strict flags enabled, I think the typings may need to be firmed up.

@stubailo
Copy link
Contributor

Let's keep track of typescript improvements in #704

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants