graphql-resolvers icon indicating copy to clipboard operation
graphql-resolvers copied to clipboard

TypeScript: Property 'mergeInfo' is missing in type 'GraphQLResolveInfo' but required in type '{ mergeInfo: MergeInfo; }

Open rwieruch opened this issue 5 years ago • 8 comments

I am using this library and for the last year I loved it. Now I am using it in a TypeScript GraphQL Server with @types/graphql-resolvers.

All my types are generated via graphql-codegen. Without combineResolvers, all types evaluate just fine. If I am using a combined resolver though, I get:

Type 'IFieldResolver<any, any, { courseId: COURSE; bundleId: BUNDLE; }>' is not assignable to type 'ResolverFn<any, {}, ResolverContext, RequireFields<MutationCreateFreeCourseArgs, "courseId" | "bundleId">> | StitchingResolver<...> | undefined'.
  Type 'IFieldResolver<any, any, { courseId: COURSE; bundleId: BUNDLE; }>' is not assignable to type 'ResolverFn<any, {}, ResolverContext, RequireFields<MutationCreateFreeCourseArgs, "courseId" | "bundleId">>'.
    Types of parameters 'info' and 'info' are incompatible.
      Type 'GraphQLResolveInfo' is not assignable to type 'GraphQLResolveInfo & { mergeInfo: MergeInfo; }'.
        Property 'mergeInfo' is missing in type 'GraphQLResolveInfo' but required in type '{ mergeInfo: MergeInfo; }'.ts(2322)
Interfaces.d.ts(59, 5): 'mergeInfo' is declared here.
gen-types.ts(288, 3): The expected type comes from property 'createFreeCourse' which is declared here on type 'WithIndex<{ _?: ResolverFn<any, {}, ResolverContext, {}> | StitchingResolver<any, {}, ResolverContext, {}> | undefined; ... 8 more ...; createAdminCourse?: ResolverFn<...> | ... 1 more ... | 

Whereas I think the crucial part is:

Property 'mergeInfo' is missing in type 'GraphQLResolveInfo' but required in type '{ mergeInfo: MergeInfo; }'.ts(2322)

Could it be that the 4th argument of a resolver isn't evaluated in the TS version of this library?


Something related in another library: https://github.com/prisma-labs/graphql-middleware/pull/29/files

rwieruch avatar Feb 03 '20 13:02 rwieruch

@rwieruch are you TypeScript acknowledged? I've being using for a while, but I'm no expert. To give you context: this library has currently no typings at all, and I don't even know where to start with typing cause this library has no direct relation with GraphQL. Take combineResolvers, for instance:

combineResolvers: (...args: any[]) => Promise<any>

The any[] is because this is precisely how this library works: whatever it takes in, it will manage to make available to the end of the cycle.

We could use generics an inference to help typing resolver implementations from whatever is arguments are passed into combineResolvers, but I'm not really sure how to accomplish that. I'm very open to PRs, though.

P.s.: a easy solution for you own case would be to create your own strict type definition... keep in mind this wouldn't be a got fit for contributing, cause this varies a lot. context, for instance, is basically a black box for typing, no way we should interfere on how that is typed, or we would probably cause more trouble than gain.

lucasconstantino avatar Feb 04 '20 12:02 lucasconstantino

@lucasconstantino thanks for taking the time to respond! There are types for your library: https://www.npmjs.com/package/@types/graphql-resolvers Someone must have published them :-)

I was just wondering if this was a bug with the published types. Seems like it didn't come from you. Just wanted to leave this issue here if anyone stumbles upon it as well and would be open to create a PR for it. Maybe I am just wrong and the typings from @types/graphql-resolvers are already alright. I am no TS expert, so I would love as well if someone would take over here :)

rwieruch avatar Feb 04 '20 13:02 rwieruch

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/44919

zaguiini avatar May 20 '20 13:05 zaguiini

Types have been published. Can you try it again?

zaguiini avatar May 21 '20 20:05 zaguiini

Not 100% sure if it's the same issue, but it looks very related:

Type 'IFieldResolver<any, ResolverContext, any, any>' is not assignable to type 'IResolverObject<any, any, any> | IResolverOptions<any, any, any> | IFieldResolver<any, any, any>'.
              Type 'IFieldResolver<any, ResolverContext, any, any>' is not assignable to type 'IFieldResolver<any, any, any>'.
                Types of parameters 'info' and 'info' are incompatible.
                  Type 'GraphQLResolveInfo & { mergeInfo: MergeInfo; }' is not assignable to type 'GraphQLResolveInfo & { mergeInfo?: MergeInfo; }'.
                    Type 'GraphQLResolveInfo & { mergeInfo: MergeInfo; }' is not assignable to type 'GraphQLResolveInfo'.
                      Types of property 'returnType' are incompatible.
                        Type 'import("/Users/nephix/Projects/boilerplate-server/node_modules/graphql/type/definition").GraphQLOutputType' is not assignable to type 'import("/Users/nephix/Projects/boilerplate-server/node_modules/@types/graphql-resolvers/node_modules/graphql/type/definition").GraphQLOutputType'.
                          Type 'GraphQLObjectType<any, any>' is not assignable to type 'GraphQLOutputType'.
                            Type 'GraphQLObjectType<any, any>' is not assignable to type 'GraphQLObjectType<any, any, { [key: string]: any; }>'.
                              Types of property 'isTypeOf' are incompatible.
                                Type 'import("/Users/nephix/Projects/boilerplate-server/node_modules/graphql/type/definition").GraphQLIsTypeOfFn<any, any>' is not assignable to type 'import("/Users/nephix/Projects/boilerplate-server/node_modules/@types/graphql-resolvers/node_modules/graphql/type/definition").GraphQLIsTypeOfFn<any, any>'.
                                  Types of parameters 'info' and 'info' are incompatible.
                                    Property 'cacheControl' is missing in type 'import("/Users/nephix/Projects/boilerplate-server/node_modules/@types/graphql-resolvers/node_modules/graphql/type/definition").GraphQLResolveInfo' but required in type 'import("/Users/nephix/Projects/boilerplate-server/node_modules/graphql/type/definition").GraphQLResolveInfo'.

Getting this with:

  • "@types/graphql-resolvers": "^0.3.0",
  • "graphql-resolvers": "^0.4.2",
  • "apollo-server-express": "^2.19.0",
  • "typescript": "^4.1.2"

nephix avatar Dec 12 '20 10:12 nephix

@nephix I'm having this same problem right now, did you figure out how to fix it ?

96erardo avatar May 09 '21 23:05 96erardo

@GerardoAGL96 i stopped using this lib and wrote my own TS version of it. Don't have access to the code anymore though, sorry

But if you take a look at the source of this lib it shouldn't be hard. That's at least how I did it

nephix avatar May 10 '21 10:05 nephix

@nephix I'm having this same problem right now, did you figure out how to fix it ?

I have this issue and bypassed it for the day by editing the type in the index.d.ts file provided by @types/graphql-resolvers I also added an issue on the specific topic https://github.com/lucasconstantino/graphql-resolvers/issues/34 It needs to be addressed in by someone who understands this better than me. repo https://www.npmjs.com/package/@types/graphql-resolvers

dan-lutd avatar Jul 28 '21 14:07 dan-lutd