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

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

Open
rwieruch opened this issue Feb 3, 2020 · 8 comments · Fixed by DefinitelyTyped/DefinitelyTyped#44919

Comments

@rwieruch
Copy link

rwieruch commented Feb 3, 2020

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

@lucasconstantino
Copy link
Owner

@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.

@rwieruch
Copy link
Author

rwieruch commented Feb 4, 2020

@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 :)

@zaguiini
Copy link

@zaguiini
Copy link

Types have been published. Can you try it again?

@nephix
Copy link

nephix commented Dec 12, 2020

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"

@96erardo
Copy link

96erardo commented May 9, 2021

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

@nephix
Copy link

nephix commented May 10, 2021

@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

@dan-lutd
Copy link

@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

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

Successfully merging a pull request may close this issue.

6 participants