-
Notifications
You must be signed in to change notification settings - Fork 54
Duplicate IResolvers definitions breaks build #470
Comments
I'm able to work around this by backing up the graphqlgen dependency for one of the two packages involved to a version that doesn't output the graphql-tools declaration. However, the It seems like the |
Hey @jbreeden-splunk, the problem it addresses is #15 I don't have time to dive into the issue right now, but will try to loop back tonight. Any ideas you have to possibly address this issue are welcome. |
Thanks for the quick response, @jasonkuhrt If I've understood correctly, we're trying to allow graphqlgen resolvers to be compatible with graphql-tool's IResolvers interface, so that you can pass them to The problem with the chosen approach is that globally swapping the types of a 3rd party package with fundamentally incompatible types is always going to cause problems for larger apps. These apps are often composed of many packages making it impossible for graphqlgen to predict the full context under which the altered types are being used. IMO a safer approach would simply be to make the types actually compatible. If the only problem is the missing index signature, we could simply add it. I did see your note in #15:
And I agree with the sentiment regarding the black box, but the fact is it is a black box to graphql-tools, and if you wish to be compatible I think it would be more appropriate to alter your own type definitions, rather than theirs. If it's that much of a sticking point, I would recommend documenting the module declaration or type assertion workarounds, but not including them in the codegen with no way to disable it. Hope that's somewhat helpful ¯\_(ツ)_/¯ |
@jbreeden-splunk thanks for sharing your perspective, it was helpful! I appreciate your point. In general, it is what I thought and think too. In practice, I would be interested in seeing a project that needs the unsafe version of
To my knowledge this is a novel use-case. Thanks for bringing it to light. I would like to understand it better. Is the consuming project of these two packages itself a graphqlgen project? I believe one solution may be to make it so that by default graphqlgen does not generate its own specification for compatibleIResolvers: yes Imagining we had this solution for a moment, in your case @jbreeden-splunk, assuming your root project is a graphqlgen one (question above) would you enable the option in your project? If not, why? |
Yes, it is. Basically I have a monorepo setup like this:
Both of these packages use graphqlgen to generate resolver type definitions, so they both contain the graphql-tools declaration in graphqlgen.ts.
That would work for me. If the option was there, I would probably leave it disabled for all packages and just perform the requisite type assertion when passing the resolvers to graphql-tools. Even in the root package, my merged resolvers object is not going to conform to the generated |
Good to know, I think this is a reasonable approach for this project to take presently. I also believe it should be opt-in, not opt-out, due to the leaky abstraction we both agree it represents.
👍
Out of curiosity and trying to understand your use-case better;
I will aim to have a fix for this merged and released by next Sunday. Pull-requests welcome in the meantime. |
Awesome, thanks for the help!
It has its own resolvers, in addition to merging in schema from sub-packages.
Right now it's just one big SDL file. We're looking at switching to resolver-first development with Nexus, but haven't yet. |
@jasonkuhrt Just noticed the I tried to disable it, but graphqlgen yells at me saying it's unrecognized:
Even though it is definitely present (in some form) in my graphqlgen package:
It seems it's in there, but not fully implemented. Am I doing something wrong or are the docs just ahead of the actual release? (Tested on version 0.6.0-rc9) |
@jbreeden-splunk 🤦♂️ right I think that error comes from Its updated though https://github.com/prisma/graphqlgen/search?utf8=%E2%9C%93&q=iresolvers-augmentation&type= Are you using the latest version of it too ( |
@jasonkuhrt
Version is here.
Maybe graphqlgen-json-schema has not released yet? |
Hey @joe-re just fyi this project isn't maintained anymore by me. I am working on nexus oriented tools now. |
Description
Graphqlgen overrides the declaration of
IResolvers
from thegraphql-tools
package in the generatedgraphqlgen.ts
file. This causes an error when you try to compose a schema from two packages that both use graphqlgen.Each package will have a declaration like so:
Where
Resolvers
is a unique type generated within the package itself.Since IResolvers will be defined in both packages, with different definitions, you get the following error at build time:
Steps to reproduce
mergeSchemas
when starting your serviceNote, I'm not actually even using these types. Their presence in graphqlgen.ts appears to be enough to cause the error.
Expected results
No error is thrown
Actual results
TSError: ⨯ Unable to compile TypeScript
Versions
The text was updated successfully, but these errors were encountered: