Could Not Find Module for relative imports when mocking
alexanderwanyoike opened this issue · comments
Issue workflow progress
Progress of the issue based on the
Contributor Workflow
- 1. The issue provides a reproduction available on
Github,
Stackblitz
or
CodeSandbox
Make sure to fork this template and run
yarn generate
in the terminal.Please make sure Mesh package versions under
package.json
matches yours.
- 2. A failing test has been provided
- 3. A local solution has been provided
- 4. A pull request is pending review
Describe the bug
Currently trying to follow the example specified in the documentation to mock a GraphQL query. However, I ran into the following error when I try access the mesh after building it and starting the application. Things to note:
- The mesh builds correctly
- I am able to start the mesh
- However when I access the mesh it fails with The following error
/Users/****/src/gateway/dist/apps/graphql-mesh/webpack:/nodejs-express-template/.mesh/index.ts:16882
return Promise.reject(new Error(`Cannot find module '${relativeModuleId}'.`));
^
Error: Cannot find module 'mocks/userMocks.ts'.
at importFn (/Users/***/src/gateway/dist/apps/graphql-mesh/webpack:/nodejs-express-template/.mesh/index.ts:16882:29)
at tryImport (/Users/***/src/gateway/node_modules/@graphql-mesh/utils/cjs/load-from-module-export-expression.js:26:20)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at loadFromModuleExportExpression (/Users/***/src/gateway/node_modules/@graphql-mesh/utils/cjs/load-from-module-export-expression.js:13:17)
Waiting for the debugger to disconnect...
It seems that mesh cannot find the module defined in the root directory ./mocks/userMocks.ts
To Reproduce Steps to reproduce the behavior:
- Create a mesh with the following mock configuration in the
./.meshrc
#... redacted
plugins:
- mock:
mocks:
- apply: Query.user.events
custom: './mocks/userMocks.ts#events'
- Create a mock file in the location
./mocks/userMocks.ts
export default {
events: [
{
id: '1',
title: 'Test Event',
},
{
id: '2',
title: 'Test Event 2',
},
],
}
- Run
mesh build
- Run
mesh start
- Access the mesh endpoint
localhost:4000/graphql
Expected behavior
- The mock file should be found as expected
Environment:
- OS: Mac OSX Ventura 13.6
- "@graphql-mesh/cli": "^0.88.1",
- "@graphql-mesh/graphql": "^0.96.0",
- "@graphql-mesh/plugin-hive": "^0.96.5",
- "@graphql-mesh/plugin-mock": "^0.96.4",
- "@graphql-mesh/transform-filter-schema": "^0.96.0",
- "@graphql-mesh/transform-hoist-field": "^0.96.4",
- "@graphql-mesh/transform-prefix": "^0.96.0",
- "@graphql-mesh/transform-rename": "^0.96.0",
- NodeJS: 18.17.1
Additional context
- We are running our mesh as graphql handler from within a nestjs controller however I tried to run this without nestjs and got the same error
We're experiencing the same issue, also when using the initializeStore functionality.
Is there a useful workaround for this right now?
I've been creating resolvers that provide mock data and providing them with the additionalResolvers
option. The limitation there is that I cannot set preserveResolvers: false
in the mock settings, which I'd like to be able to do.
is there any update on this issue? we got the same experience
I also have this issue: import in yaml does not work for the store and the mock custom.
To be more specific, I encounter this bug when using "mesh start" but not when using "mesh dev"