graphql-modules
graphql-modules copied to clipboard
Yarn 2.0 - No provider for [object Object]!
I'm suddenly having the following error, even though I'm not doing any Dependency Injection yet. All classes that I'm importing into my resolvers are already pre-injected.
Also tried to JSON.stringify the exception error on Apollo Server Plugins, but without success.
{
"errors": [
{
"message": "No provider for [object Object]! - in Module \"auth\" (Singleton Scope) (Proxy)",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"register"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"keys": [
{
"token": {
"token": {
"_desc": "module-id"
},
"id": 0
},
"id": 1
}
],
"message": "No provider for [object Object]! - in Module \"auth\" (Singleton Scope) (Proxy)",
"stacktrace": [
"Error: No provider for [object Object]! - in Module \"auth\" (Singleton Scope) (Proxy)",
" at injectionError (/Users/macbook-user/webdev/ecommerce-ddd/.yarn/$$virtual/graphql-modules-virtual-533ebcb5a3/0/cache/graphql-modules-npm-1.0.0-alpha.2-cd255ebe7e-3876f7a968.zip/node_modules/graphql-modules/index.cjs.js:218:11)",
" at noProviderError (/Users/macbook-user/webdev/ecommerce-ddd/.yarn/$$virtual/graphql-modules-virtual-533ebcb5a3/0/cache/graphql-modules-npm-1.0.0-alpha.2-cd255ebe7e-3876f7a968.zip/node_modules/graphql-modules/index.cjs.js:204:12)",
" at ReflectiveInjector._throwOrNull (/Users/macbook-user/webdev/ecommerce-ddd/.yarn/$$virtual/graphql-modules-virtual-533ebcb5a3/0/cache/graphql-modules-npm-1.0.0-alpha.2-cd255ebe7e-3876f7a968.zip/node_modules/graphql-modules/index.cjs.js:561:19)",
" at ReflectiveInjector._getByKey (/Users/macbook-user/webdev/ecommerce-ddd/.yarn/$$virtual/graphql-modules-virtual-533ebcb5a3/0/cache/graphql-modules-npm-1.0.0-alpha.2-cd255ebe7e-3876f7a968.zip/node_modules/graphql-modules/index.cjs.js:535:21)",
" at ReflectiveInjector.get (/Users/macbook-user/webdev/ecommerce-ddd/.yarn/$$virtual/graphql-modules-virtual-533ebcb5a3/0/cache/graphql-modules-npm-1.0.0-alpha.2-cd255ebe7e-3876f7a968.zip/node_modules/graphql-modules/index.cjs.js:499:21)",
" at /Users/macbook-user/webdev/ecommerce-ddd/.yarn/$$virtual/graphql-modules-virtual-533ebcb5a3/0/cache/graphql-modules-npm-1.0.0-alpha.2-cd255ebe7e-3876f7a968.zip/node_modules/graphql-modules/index.cjs.js:503:18",
" at Array.forEach (<anonymous>)",
" at ReflectiveInjector.instantiateAll (/Users/macbook-user/webdev/ecommerce-ddd/.yarn/$$virtual/graphql-modules-virtual-533ebcb5a3/0/cache/graphql-modules-npm-1.0.0-alpha.2-cd255ebe7e-3876f7a968.zip/node_modules/graphql-modules/index.cjs.js:502:25)",
" at Function.createWithExecutionContext (/Users/macbook-user/webdev/ecommerce-ddd/.yarn/$$virtual/graphql-modules-virtual-533ebcb5a3/0/cache/graphql-modules-npm-1.0.0-alpha.2-cd255ebe7e-3876f7a968.zip/node_modules/graphql-modules/index.cjs.js:486:21)",
" at Object.ɵgetModuleContext (/Users/macbook-user/webdev/ecommerce-ddd/.yarn/$$virtual/graphql-modules-virtual-533ebcb5a3/0/cache/graphql-modules-npm-1.0.0-alpha.2-cd255ebe7e-3876f7a968.zip/node_modules/graphql-modules/index.cjs.js:846:81)"
]
}
}
}
],
"data": {
"register": null
}
}
I'm using a Yarn v2 Monorepo and I've found out that the problem was happening every-time I imported a Module created on another package.
I have a package/workspace for the Apollo Server (@package/graphql-api) and another one for handling the core business logic of my application (@package/core) from which I export the GraphQL Modules. If I define a Module directly into @package/graphql-api it works just fine, but not if:
import { AuthModule } from '@package/core'
I was able to solve the problem by installing GraphQL Modules only in the @package/core and then doing:
export * from 'graphql-modules'
So I could import in @package/graphql-api:
import { createApplication } from '@package/core'
It solved the problem, but I don't think that is a good practice.