Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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.) #2232

Open
bugoverdose opened this issue Mar 6, 2021 · 13 comments · May be fixed by #2248

Comments

@bugoverdose
Copy link

project environment: create-react-app with typescript template
dev environment: windows10, wsl2, node(14.16.0 ver), npm(7.5.6 ver)

image

  1. When I run [apollo client:codegen src/generated_api_types --target=typescript --outputFlat], it works fine. All the interfaces are generated perfectly.

  2. But if I run the same command as [npm run apollo:codegen], it doesn't work.

  3. 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?

@bugoverdose
Copy link
Author

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.

  1. [npm i apollo] : you can run apollo as a script, in a [npm run] format, but you can't run apollo in your terminal.

  2. [npm i apollo -g] : you can run apollo in your terminal, but you can't run it in a [npm run] format.

  3. [npm i apollo] & [npm i apollo -g] : same as 2.

Maybe it only happens to some computers? I can't be sure.

@ptya
Copy link

ptya commented Mar 18, 2021

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:
Screenshot 2021-03-18 at 16 00 43

@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 :)

@WIStudent
Copy link

WIStudent commented Mar 18, 2021

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"
  }

@WIStudent
Copy link

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

@WIStudent
Copy link

According to #1553 (comment) 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.

@bugoverdose bugoverdose changed the title The codegen command doesn't work propery when you run it as a script. Installing apollo globally can cause errors. (e.g., apollo client:codegen command doesn't work properly when you run it as a script.) Mar 19, 2021
@WIStudent
Copy link

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.

@WIStudent
Copy link

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)
grafik
As you can see, it only uses graphql@14.7.0.

Installing graphql@15 fails because not all peer dependencies can be satisfied:
grafik

Using the --legacy-peer-deps flag while installing results in this dependency tree:
grafik
Now everything ueses graphql@15.5.0.

I don't know how I managed to get both graphql@14.7.0 and graphql@15.5.0 in the dependency tree of my other project.

@WIStudent
Copy link

I don't know why but I can't convince npm in my other project to use graphql@15.5.0 everywhere. npm install -D graphql@15 does not throw an error and instead produces the same dependency tree ptya posted above.

@bugoverdose bugoverdose changed the title Installing apollo globally can cause errors. (e.g., apollo client:codegen command doesn't work properly when you run it as a script.) 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.) Mar 20, 2021
@abernix
Copy link
Member

abernix commented Mar 24, 2021

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 #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-config within graphql-language-server-types. Adding graphql-config into the devDependencies within 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.ts starting in 3858c09

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 (05c5c69 and 3858c09) and forming your own opinions on the right way to solve it!).

@NikhilSamuel
Copy link

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.

how to fix this

@Exkalybur
Copy link

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:

I hope this helps.

@de1eb
Copy link

de1eb commented Apr 24, 2022

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

@Neo42
Copy link

Neo42 commented May 2, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants