-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Using link/schema and @graphql-tools/schema in combination and bundled by webpack results in "Cannot use GraphQLSchema from another module or realm" #7184
Comments
Since we don't control the contents of this package, and nested subdirectories within the graphql package do not have their own package.json files with "main" and "module" entry points (like our `@apollo/client/*` sub-packages do), it is unfortunately not safe to reach into the package to import specific items, as demonstrated by apollographql#7184. This could cause a bundle size regression for bundlers that do not perform any tree-shaking, but it's the responsibility of the graphql package maintainers to support selective sub-package imports if they want to. Until that happens, @apollo/client must import from the graphql package in the only supported way: directly from the top-level package.
Since we don't control the contents of the graphql package, and nested subdirectories within the graphql package do not have their own package.json files with "main" and "module" entry points (like our @apollo/client/* sub-packages do), it is unfortunately not safe to reach into the package to import specific items, as demonstrated by #7184. This change could cause a bundle size regression for bundlers that do not perform any tree-shaking, but it's the responsibility of the graphql package maintainers to support selective sub-package imports, if they want to. Until that happens, @apollo/client must import from the graphql package in the only supported way: directly from the top-level package.
@stoically You can test the changes from #7185 using |
@benjamn Works as expected with |
Intended outcome:
Using
SchemaLink
with@graphql-tools/schema
'smakeExecutableSchema
works as expected when bundled with webpackActual outcome:
It seems that link/schema pulls in CommonJS instead of ESM when bundled with webpack, so it's different classes.
Related issue in the
@graphql-tools
repo: ardatan/graphql-tools#1790How to reproduce the issue:
Minimal repo: https://github.com/stoically/apollo-client-link-schema-webpack
Fix
Instead of directly reaching into
graphql
like soapollo-client/src/link/schema/index.ts
Lines 1 to 2 in d470c96
import from the top level, like so
Though, I guess the actual fix would be to dive into webpack and check what's going wrong
Workaround
webpack.config.js
Other things I tried which didn't work out
https://consiiii.me/2020/10/13/graphql-issue/
webpack 4.0.0-beta.0 different behavior with .mjs files webpack/webpack#6459 (comment) & https://github.com/webpack/webpack/issues/6796#issuecomment-374980347
Versions
System:
OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
Binaries:
Node: 12.18.4 - ~/.nvm/versions/node/v12.18.4/bin/node
Yarn: 1.22.10 - ~/.nvm/versions/node/v12.18.4/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v12.18.4/bin/npm
Browsers:
Chrome: 86.0.4240.75
Firefox: 81.0.2
npmPackages:
@apollo/client: 3.3.0-beta.13 => 3.3.0-beta.13
The text was updated successfully, but these errors were encountered: