-
Notifications
You must be signed in to change notification settings - Fork 237
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
fix(): move graphql dependency back to dev deps #711
Conversation
I don't remember what was the actual problem but it did not work as expected across the various package managers and node versions. @simone-sanfratello did you recall what was the problem you had? |
pretty sure it loads the graphql v15 from graphql-jit, instead of the actual v16 required install graphql v16 as dependency should fix it |
@simone-sanfratello why not leave the Also, assuming that this package requires GraphQL^16, package managers should be smart enough to not pull GraphQL v15 from graphql-jit if the peer dependency is specified as follows: |
which version of npm are you using? Not sure, but it works in different ways in v6 and v7 and v8 |
Shouldn't this package work for all these NPM versions? Correct me if I'm wrong but I think we leave out what is most important here - once you define a package as a "dependency" in the package.json file, adding it as a "peerDependency" does not change anything so essentially "graphql" is now registered as an internal dependency of "mercurius" ("peerDependencies" part is ignored in this case). If you look at graphql-tools monorepo (example: https://github.com/ardatan/graphql-tools/blob/master/packages/utils/package.json) every package defines "graphql" as a peer dependency to make sure they all (when used) are using the same version of the core (graphql) package. Not sure how NPM version is relevant to this issue (I suspect graphql package is being automatically hoisted in one of the versions you've mentioned and that's why this issue isn't reproducible everywhere). Perhaps this is something that should be investigated at the package manager level (to make sure |
because mercurius v9 specifically requires graphql v16, that's why. It doesn't work with any version of graphql, so it need a strict dependency so, moving to a dev dep will cause in the final application an unwanted behavior very hard to understand |
Having If you look at the graphql-tools repository (I'm using it just as an example), you'll notice that all these packages do require using GraphQL^16 as well (and their latest versions won't work properly with, for example, GraphQL^15). This is also why they have
How come? If you're assuming that library users will ignore errors printed out by package managers (which is quite an odd assumption but let's say they do), you can always add an extra runtime check. This is exactly why |
I'll spend some time in the weekend to show how peerDep is not enough, and to check if it works in a different way in npm v6 and above - I guess so, but I'm not sure |
Thanks @simone-sanfratello BTW I just noticed that the graphql-jit also defines |
this is the situation as is, with
that's why we need this, without the explicit grapqhql dedendency this is really hard to debug #693 we can require to install
but mercurius works with the precise version of graphql, so it has to be a dependency note: it works in the same way with npm v6, v7 and v8 |
I think you might have misunderstood what "peerDependency" means. Every peer dependency must be explicitly installed to ensure that the same behavior is encountered between different package managers.
In this issue, you mentioned "the issue is caused by using graphql-jit that uses graphql@15" which isn't correct: https://github.com/zalando-incubator/graphql-jit/blob/main/package.json#L49 (please note ">="). If you still disagree, please, feel free to close this PR. I feel like I've already spent enough time explaining why the current configuration is invalid. |
I'm not a maintainer of this module, but I guess your PR is not going to be merged because it doesn't pass tests. You were right if Even worse, having Now we can endlessly be arguing about how peer dependencies should work and how actually work, but the fact that code must work remain. |
Something that would be useful is to have a repro where the current setup would fail. |
Hiya 👋 I've spent way much time fighting peer dependency errors, so happy to lend a hand here. I think the flip side of what Matteo says ("a reproduction for when current approach fails") should be the next step. When does having it as a peer fail. The issue with the current approach (as has been discussed in this issue) is that the peer dependency essentially does nothing, and what you want is for users to provide their own version of One concrete example is #711 (comment), which is fixed by zalando-incubator/graphql-jit#156. If there are other cases (unfortunately, tracking down peer dependency errors is often an exercise in whack-a-mole) we should fix those as they crop up. As an example, running
So we have warnings for $ rg graphql-tools
examples/executable-schema.js
5:const { makeExecutableSchema } = require('@graphql-tools/schema')
docs/api/options.md
335:const { makeExecutableSchema } = require('@graphql-tools/schema')
package.json
32: "@graphql-tools/merge": "^8.0.0",
33: "@graphql-tools/schema": "^8.0.0",
34: "@graphql-tools/utils": "^8.0.0",
44: "graphql-tools": "^8.0.0",
test/app-decorator.js
12:const { makeExecutableSchema } = require('@graphql-tools/schema')
test/directives.js
7:const { makeExecutableSchema } = require('@graphql-tools/schema')
8:const { mergeResolvers } = require('@graphql-tools/merge')
15:} = require('@graphql-tools/utils')
test/hooks.js
6:const { mapSchema } = require('@graphql-tools/utils')
test/types/index.ts
12:import { makeExecutableSchema } from '@graphql-tools/schema'
13:import { mapSchema } from '@graphql-tools/utils' |
I would go ahead and drop graphql from the peerDependencies. |
That's not the correct solution as there needs to be only one instance of |
I do not understand this. What is the goal? "bring your own version" sounds like a maintenance nightmare to me. I do not wish to guarantee support for anything but what Mercurius is tested on. In my opinion the whole "bring your version" of graphql does not really work as expected in the ecosystem: the issue on graphql-jit is an example of that. Changing this module would not have prevented that problem either. Specifying it as a dependency has the benefit of making the install of graphql automatic for npm v6 users, which is still the default version of npm in Node v14 and its usage is still very widespread. This specific problem will disappear with node v16. |
As I've mentioned in my comments above, there're several ways of specifying what versions are supported (and tested) without setting |
I'm very familiar about the mechanisms. I do not understand what use cases this specific way does not cover. Is it a yarn1 issue? a yarn2 issue? a pnpm issue? is it a typescript issue? If all dependencies agrees on the same version range, then the package manager hoist the dependency and it's one and the same everywhere. The current code works and all the tests are passing with the default version of the package manager in all supported runtimes. How can I reproduce a situation where it fails? |
Any news about this issue? I'm getting the same error 😕 |
Update your dependencies and the error should disappear. |
I second this and here's why:
This would not solve above issue as It would also not solve the issue of incompatible types between my directly referenced From @mcollina in #956 (comment):
This is true, and With So:
|
Ok, let's do the |
This shipped |
Current behavior
I've just noticed that the
graphql
package is currently defined as both "dependency" and a "peerDependency" (at the same time) which implicitly means it's no longer a "peer dependency" as it will be auto-installed by package managers as an internal mercurius' dependency.This has been already fixed in the past but it was reverted back in this PR #565
Expected behavior
graphql
should be listed as adevDependency
so it gets auto-installed for those who want to contribute. For package consumers though, it should be defined as a peer dependency, otherwise, you may run into the following issue:Great work on this package @mcollina!