https://serverless-stack.com/ logo
#help
Title
# help
b

Bshr Ramadan

04/14/2022, 5:17 AM
Hello I am trying to move from cjs to esm I am using Apollo graphql and this error is bringing on lambda invokes:
Copy code
Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Cannot use GraphQLNonNull \"Boolean!\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\n<https://yarnpkg.com/en/docs/selective-version-resolutions>\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results.","reason":"Error: Cannot use GraphQLNonNull \"Boolean!\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\n<https://yarnpkg.com/en/docs/selective-version-resolutions>\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities 
and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results.","promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: Cannot use GraphQLNonNull \"Boolean!\" from another module or realm.","","Ensure that there is only one instance of \"graphql\" in the node_modules","directory. If different versions of \"graphql\" are the dependencies of other","relied on modules, use \"resolutions\" to ensure only one version is installed.","","<https://yarnpkg.com/en/docs/selective-version-resolutions>","","Duplicate \"graphql\" modules cannot be used at the same time since different","versions may have different capabilities and behavior. The data from one","version used in the function from another could produce confusing and","spurious results.
I tried to use yarn resolutions like this:
Copy code
"resolutions": {
    "graphql": "15.5.1"
  }
But It didn't solve the problem. I have monorepo, and I tried to unify versions of many related dependencies between repos did anyone faced this?
This is how package.json looks like
Copy code
{
  "dependencies": {
    "@apollo/gateway": "^0.42.0",
    "apollo-server-env": "^4.0.3",
    "apollo-server-lambda": "^2.23.0",
    "aws4": "^1.11.0",
    "cordova-common": "^1.0.0",
    "graphql": "^15.5.1",
    "graphql-scalars": "^1.9.0",
    "make-fetch-happen": "^8.0.14",
    "ramda": "^0.27.1"
  },
  "devDependencies": {
    "chai": "^4.3.4",
    "chai-as-promised": "^7.1.1",
    "chai-like": "^1.1.1",
    "chai-spies": "^1.0.0",
    "chai-subset": "^1.6.0",
    "chai-things": "^0.2.0",
    "eslint": "^7.23.0",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-config-airbnb-base": "^14.2.1",
    "eslint-loader": "^4.0.2",
    "eslint-plugin-import": "^2.22.1",
    "mocha": "^8.3.2"
  },
  "resolutions": {
    "graphql": "15.5.1"
  }
}
d

Derek Kershner

04/14/2022, 1:57 PM
Many. Publish Apollo Server packages in ESM · Issue #5627 · apollographql/apollo-server (github.com)
You cannot, to my knowledge, use ESM and Apollo together.
b

Bshr Ramadan

04/14/2022, 4:19 PM
hmm I see, I am thinking if I exclude apollo dependencies from bundling and add it to the node_modules zip does that effect the performance ? @Derek Kershner
d

Derek Kershner

04/14/2022, 4:21 PM
no idea, I moved to not using Apollo instead, and just using graphql-tools directly.
its a similar strategy to what SST is going to publish soon as an example. linking @thdxr, as maybe its been published now.
t

thdxr

04/14/2022, 4:24 PM
Yeah we abandoned Apollo once we discovered how unfriendly their setup is for ESM
our gql stack still not released but targeting end of April now
Using gql tools directly is a great option
that’s the best example you are going to get for now @Bshr Ramadan
b

Bshr Ramadan

04/14/2022, 5:07 PM
Sounds a great option, but I don't know if moving from apollo federation to graphql-tools is a straight forward step or not,I will give it a try Thanks for your help @Derek Kershner @thdxr
t

thdxr

04/14/2022, 5:11 PM
It's very straightforward! Apollo is actually doing very little it's why we we're able to replace it without much effort
b

Bshr Ramadan

04/14/2022, 5:12 PM
That's very good @thdxr
d

Derek Kershner

04/14/2022, 5:26 PM
I am not using federation, so I am not sure how easy that would be, but frankly you could probably maintain apollo for federation and just run that app using
cjs
, and make the others graphql-tools and
esm
b

Bshr Ramadan

04/14/2022, 8:02 PM
hmm you mean to keep the apollo gateway only, and other services move graphql-tools? @Derek Kershner
d

Derek Kershner

04/14/2022, 8:04 PM
that exactly
Dax seemed to think it was easy though, but not sure he caught the word “federation”.
t

thdxr

04/14/2022, 8:28 PM
oh I did miss the word federation 😅
I use pothos so I would try out this plugin: https://pothos-graphql.dev/docs/plugins/federation
5 Views