benawad / apollo-mocked-provider

Automatically mock GraphQL data with a mocked ApolloProvider
MIT License
92 stars 25 forks source link

fix: import of graphql-tools to work with webpack #29

Closed sarfata closed 4 years ago

sarfata commented 4 years ago

I made a last minute mistake when I was cleaning up yesterday.

It's very important to not import graphql-tools because it references the package resolve-from which confuses webpack and causes an error. (We also get a ton of warnings because other parts of graphql-tools use conditionals require which webpack also does not like).

It's possible to make webpack ignore it but it's going to be easier for everyone if we just avoid the problem by importing the sub-pieces of graphql-tools we do need (and the sub-pieces do not refer the problematic packages).

I think with this commit message and the semantic-release gh action we should get a 4.0.1 automatically so I have not updated the version number.

For reference this is the error I get in my project when I use apollo-mocked-provider 4.0.0 as it is now:

ERROR in ../node_modules/resolve-from/index.js
Module not found: Error: Can't resolve 'module' in '/Users/thomas/work/chartedsails/node_modules/resolve-from'
 @ ../node_modules/resolve-from/index.js 3:15-32
 @ ../node_modules/@graphql-tools/import/index.esm.js
 @ ../node_modules/apollo-mocked-provider/node_modules/graphql-tools/index.esm.js
 @ ../node_modules/apollo-mocked-provider/dist/apollo-mocked-provider.es.production.js
 @ ./src/backend/__mocks__/gqlmocks.tsx
sarfata commented 4 years ago

So the can't resolve 'module' error is because of my webpack configuration. I needed to ignore the 'module' node package like create-react-app does.

But even with that fix, I still get warnings from the other graphql-tools packages listed above and runtime issues in storybook:

TypeError: Cannot read property 'native' of undefined
    at Object.../node_modules/fs-extra/lib/fs/index.js (http://localhost:9009/vendors~main.870fed89a175efef8db3.bundle.js:393787:24)
    at __webpack_require__ (http://localhost:9009/runtime~main.870fed89a175efef8db3.bundle.js:849:30)
    at fn (http://localhost:9009/runtime~main.870fed89a175efef8db3.bundle.js:151:20)
    at Object.../node_modules/fs-extra/lib/index.js (http://localhost:9009/vendors~main.870fed89a175efef8db3.bundle.js:393806:6)
    at __webpack_require__ (http://localhost:9009/runtime~main.870fed89a175efef8db3.bundle.js:849:30)
    at fn (http://localhost:9009/runtime~main.870fed89a175efef8db3.bundle.js:151:20)
    at Module.<anonymous> (http://localhost:9009/vendors~main.870fed89a175efef8db3.bundle.js:167709:66)
    at Module.../node_modules/@graphql-tools/import/index.esm.js (http://localhost:9009/vendors~main.870fed89a175efef8db3.bundle.js:168201:30)
    at __webpack_require__ (http://localhost:9009/runtime~main.870fed89a175efef8db3.bundle.js:849:30)
    at fn (http://localhost:9009/runtime~main.870fed89a175efef8db3.bundle.js:151:20)

tldr: we should merge the fix. it's very simple and I get no warnings or errors with it.

github-actions[bot] commented 4 years ago

:tada: This PR is included in version 4.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: