apollo-tooling
apollo-tooling copied to clipboard
Both graphql@14 and graphql@15 are installed when installing apollo. (e.g., apollo client:codegen command doesn't work properly when you run it as a script.)
project environment: create-react-app with typescript template dev environment: windows10, wsl2, node(14.16.0 ver), npm(7.5.6 ver)

-
When I run [apollo client:codegen src/generated_api_types --target=typescript --outputFlat], it works fine. All the interfaces are generated perfectly.
-
But if I run the same command as [npm run apollo:codegen], it doesn't work.
-
The same problem arises if remove the --outputFlat option, so I guess that's not the cause.
Also, I found another person with the same issue online. Can someone help me how to fix it?
I fixed the bug in my project. Apparently, it happened because I installed apollo both in my project & globally.
I did some experiments and this was the result.
-
[npm i apollo] : you can run apollo as a script, in a [npm run] format, but you can't run apollo in your terminal.
-
[npm i apollo -g] : you can run apollo in your terminal, but you can't run it in a [npm run] format.
-
[npm i apollo] & [npm i apollo -g] : same as 2.
Maybe it only happens to some computers? I can't be sure.
I also face this issue. It occurs when I am installing graphql@15 as it results having 2 versions of graphql installed in node_modules folder locally:

@apollo-language-server has a dependency only supporting graqhql ^14.x which I think causes this.
It works for me if I downgrade to v14 of graphql, but it's bugging me as I can't use the latest graphql package due to a script I need to run locally :)
I am having the same problem.
This does not seem to be caused directly by apollo-language-server because it accepts the latest version of graphql.
// apollo-language-server/package.json
"dependencies": {
"graphql": "14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0"
}
The issue seems to be caused by @apollographql/graphql-language-service-interface and its dependencies @apollographql/graphql-language-service-parser, @apollographql/graphql-language-service-types and @apollographql/graphql-language-service-utils. They all do not accept graphql@15 as peer dependency
"peerDependencies": {
"graphql": "^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"
}
These packages all link to non existing github repositories and were not updated in 2 years. https://www.npmjs.com/package/@apollographql/graphql-language-service-interface https://www.npmjs.com/package/@apollographql/graphql-language-service-parser https://www.npmjs.com/package/@apollographql/graphql-language-service-types https://www.npmjs.com/package/@apollographql/graphql-language-service-utils
According to https://github.com/apollographql/apollo-tooling/issues/1553#issuecomment-571303621 these packages are forks from https://github.com/graphql/graphiql/tree/main/packages. The original packages support graphql@15 by now so I think it would be helpful if an apollographql member could take a look at the original packages and update the packages under the @apollographql namespace accordingly.
By the way this is not an issue with installing apollo globally, this issue also occurs locally on my installation. The issue is that apollo-language-server claims to be compatible with graphql@15 in its package.json while its dependencies are not. This might also be related to npm 7 because it will install peer dependencies automatically and the packages listed above define graphql as peer dependency. This might cause npm to install both graphql@14 and graphql@15.
Installing apollo in an empty project (node v15.12.0, npm 7.6.3) resulted in the following dependency tree for me (calling npm ls graphql)
As you can see, it only uses [email protected].
Installing graphql@15 fails because not all peer dependencies can be satisfied:

Using the --legacy-peer-deps flag while installing results in this dependency tree:
Now everything ueses [email protected].
I don't know how I managed to get both [email protected] and [email protected] in the dependency tree of my other project.
I don't know why but I can't convince npm in my other project to use [email protected] everywhere. npm install -D graphql@15 does not throw an error and instead produces the same dependency tree ptya posted above.
Thanks for logging this issue!
We should probably get away from using the packages under the @apollographql/ namespace and switch to the upstream forks. I took a spike on that in a time-boxed amount of time that I had and was able to get to a decent place — that can be seen on this Draft PR https://github.com/apollographql/apollo-tooling/pull/2248, though you can see I quickly started getting into some controversial changes that need more work when working through these:
- First, I ran into a type dependency on
graphql-configwithingraphql-language-server-types. Addinggraphql-configinto thedevDependencieswithin the root of the monorepo allowed TypeScript to compile through that. - I then ran into a variety of typing changes in
packages/apollo-language-server/src/languageProvider.tsstarting in https://github.com/apollographql/apollo-tooling/commit/3858c09157195eebd2869f759eb72bf27532804d
Anyone experiencing this problem willing to to checkout this branch and see if they can reason their way through what appear to be largely TypeScript warnings? I'd suggest reverting both of the commits that I'd noted with controversial in the commit message (https://github.com/apollographql/apollo-tooling/commit/05c5c69e8cf7397571805239b359918e3eb24317 and https://github.com/apollographql/apollo-tooling/commit/3858c09157195eebd2869f759eb72bf27532804d) and forming your own opinions on the right way to solve it!).
By the way this is not an issue with installing apollo globally, this issue also occurs locally on my installation. The issue is that
apollo-language-serverclaims to be compatible withgraphql@15in itspackage.jsonwhile its dependencies are not. This might also be related to npm 7 because it will install peer dependencies automatically and the packages listed above definegraphqlas peer dependency. This might cause npm to install bothgraphql@14andgraphql@15.
how to fix this
Hey guys, if you are still experiencing this issue where there are multiple GraphQL versions installed and specifically the GraphQL 14.7 from apollo-language-server. This is what worked for us:
-
NPM
- Make sure you install npm >= 8.3.0
- npm added
overrides, which is equivalent forresolutionsin yarn. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides - We added overrides for graphql and ran npm install, it forced all the dependencies to use the same version of graphql as we do in our project.
-
Yarn
- Use yarn
resolutionsto force specific graphql version. https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/#toc-how-to-use-it
- Use yarn
I hope this helps.
upgrade npm for using overrides npm install -g npm
modify graphql version "graphql": "^15.8.0" and add below in package.json
"overrides": { "@apollographql/graphql-language-service-interface": { "graphql": "$graphql" }, "@apollographql/graphql-language-service-parser": { "graphql": "$graphql" }, "@apollographql/graphql-language-service-types": { "graphql": "$graphql" }, "@apollographql/graphql-language-service-utils": { "graphql": "$graphql" } }
and then delete apollo and reinstall it. It will overrides dependency and you can see it(npm ls graphql) then you can use apollo code generator
upgrade npm for using overrides npm install -g npm
modify graphql version "graphql": "^15.8.0" and add below in package.json
"overrides": { "@apollographql/graphql-language-service-interface": { "graphql": "$graphql" }, "@apollographql/graphql-language-service-parser": { "graphql": "$graphql" }, "@apollographql/graphql-language-service-types": { "graphql": "$graphql" }, "@apollographql/graphql-language-service-utils": { "graphql": "$graphql" } }and then delete apollo and reinstall it. It will overrides dependency and you can see it(npm ls graphql) then you can use apollo code generator
@de1eb Brilliant! Works like a charm!