-
-
Notifications
You must be signed in to change notification settings - Fork 522
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
feat: make GraphQL a peer dependency, support GraphQL v15.0 #1356
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 7a8482a:
|
The Sandbox template will need to be updated to include |
I will update the sandbox once this is merged. |
The 'graphql' code that is needed at runtime will be dynamically loaded. Existing static imports of 'graphql' are designated as type imports.
@kettanaito have you had a chance to review the latest changes? |
@@ -116,6 +115,7 @@ | |||
"eslint-plugin-prettier": "^3.4.0", | |||
"fs-extra": "^10.0.0", | |||
"fs-teardown": "^0.3.0", | |||
"graphql": "^16.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to migrate to v16 given the optional range is 15/16? Are there any features that are dropped in v16 that we may accidentally rely upon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since v16 is the version that MSW has used in the latest release, I think it makes sense to keep it as the devDependency version.
There are two main changes in this PR that affect run-time compatibility:
- Changing usage of
OperationTypeNode
from enum to string - The
parse
function
Changing OperationTypeNode
should be safe to do, the enum
in v16 maps to the same strings that were used in v15.
The parse
function from graphql
is the only piece of runtime code that is actually used by MSW. It's being used to get the OperationDefinitionNode
for the GraphQL operation that is intercepted. From what I can tell, the fields that MSW is interested in on OperationDefinitionNode
are unchanged between v15 and v16.
Based on this, I think it should be safe to list v15 as a dependency.
It's also worth noting that v15 is, at the time of writing, the most commonly downloaded version of graphql
on NPM (3+ million downloads a week, compared to ~2 million for v16). It would be good to be backwards compatible with v15, because lots of MSW users probably have that version in their projects.
Hey, @JohnDaly. I've finally got to review the changes you've made and they are great! I've left two questions:
|
@kettanaito Let me know if you have any follow-up questions on this |
Thank you for the superb improvement, @JohnDaly! 🎉 Feel free to tackle any other tasks as long as they look interesting to you. I know I could use your help. Thanks. |
Released: v0.45.0 🎉This has been released in v0.45.0! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
This is the misuse of peer dependencies. Please read the docs about peer deps and revert this change as the testing helper shouldn't require projects to install
|
As an example for what now happens in a project that doesn’t use/need graphql during build:
|
Another example, here is what
|
To clarify my previous comment. What this PR and
IMO It doesn't make sense to require |
Thanks for your concern, @limonte. What is the correct way to express the MSW-graphql dependency then? Because I think NPM, as a package manager, severely lacks in the means of expressing this kind of dependencies. To be absolutely clear:
If anyone has a better way to express this relationship, the pull requests are open and your contribution would be highly valued. As to the compilation issues, those happen because
We can no longer import things from |
This was never the intention. We've spent a lot of time testing this but this still slipped through. I'd appreciate if everyone stopped treating this as a deliberate shortcoming and expressed an ounce of compassion for people trying to make this package better. Thanks. |
I'm not going to revert anything. 0.45.0 only introduces the |
Thank you for the replies @kettanaito 🙏 I won't be able to contribute, but IMO graphql API should be separated from the core package and imported like this: import { graphql } from 'msw/graphql' similar to import { setupServer } from 'msw/node' In this case the And from the users' perspective graphql types will be imported from whatever version they have installed in their project. |
That's the issue though. We need to specify the supported range for GraphQL you can use with MSW. We can't guarantee that new features in GraphQL 17 won't break MSW (imagine GraphQL renames the Moving the GraphQL to |
And, once again, the issue is actually with bundling and TypeScript, not NPM. And so the solution should likely be in those areas. But, as I've said, I have no interest in working on this, so it's up to everyone to contribute with ideas and fixes. |
The
graphql
package throws errors if it's not treated as a singleton dependency. It's recommended for libraries to install it as a peer dependency (see: graphql/graphql-js#594 (comment)).To allow MSW to work with projects that are using
graphql
v15, I've made a few small changes to the code to avoid usingOperationTypeNode
as an enum. The updated code is compatible with both v15 and v16 of thegraphql
package.