apollo-tooling: apollo codegen:generate doesn't work in npm run-scripts
on osx, running “apollo codegen:generate --target=typescript --addTypename” in terminal works but putting it in package.json scripts and use “npm run” to execute the exact same command will report an error as below:
✖ Generating query files with ‘typescript’ target → Cannot query field “xxx” on type “Query” GraphQLError: Cannot query field “xxx” on type “Query” at Compiler.compileSelection (~/node_modules/apollo-codegen-core/lib/compiler/index.js:120:27) at selections.selectionSetNode.selections.map.selectionNode (~/node_modules/apollo-codegen-core/lib/compiler/index.js:106:76)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 25 (1 by maintainers)
Commits related to this issue
- fix: resolve apollo and graphql versions problem ref. https://github.com/apollographql/apollo-tooling/issues/630#issuecomment-460094221 — committed to piglovesyou/react-starter-kit by deleted user 5 years ago
- fix: resolve apollo and graphql versions problem ref. https://github.com/apollographql/apollo-tooling/issues/630#issuecomment-460094221 — committed to piglovesyou/react-starter-kit by deleted user 5 years ago
- fix: resolve apollo and graphql versions problem ref. https://github.com/apollographql/apollo-tooling/issues/630#issuecomment-460094221 — committed to piglovesyou/react-starter-kit by piglovesyou 5 years ago
- Improve feature/apollo-pure (#1720) * small README.md grammar change (#1675) * Upgrade all dependencies including Babel 7 (#1673) * Upgrade all dependencies including Babel 7 1. ncu --upgrad... — committed to kriasoft/react-starter-kit by piglovesyou 5 years ago
Ran into this issue today. I was getting this error after running:
yarn add graphql apollo
.Solution was to remove both packages:
yarn remove graphql apollo
.Then install the same version of
graphql
thatapollo
uses:yarn add graphql@~14.2.1 apollo
.Looks like the dependency on graphql was properly unpinned for a bit, but then repinned on PR #952. No idea what’s going on with their build system, but why does
graphql
have to be pinned to a very specific version for everyone that is using the Apollo tooling at all. I guess this wouldn’t matter if users were only installingapollo
globally, but this completely busts up any project that installsapollo
viadevDependencies
.This is what solved it for me in my project after lots of trial and error:
npm uninstall
bothapollo
andgraphql
from your projectnpm install graphql@14.0
npm install apollo
The key is to install
graphql
beforeapollo
. In my case,codegen
broke whengraphql
was upgraded to 14.1.1 afterapollo
was upgraded to 2.4.3. Simply reverting back tographql@14.0
didn’t work for me.For good measure (at least for the time being), I would also pin
"graphql": "~14.0.2"
inpackage.json
.This is what
npm ls
should look like:@malimccalla thanks that worked for me as hacky as it is 😕 .
Is it me or is the the Apollo project going through a phase of major change right now, a lot of their docs/examples seem out of date see:
Should probably ask this on slack but just trying to quickly gauge the situation.
@sh thanks for the quick feedback! Sorry about the trouble this was causing, honest mistake on my part.
For those of you following along,
apollo@2.5.0
should resolve this issue as @sh mentioned! I’m going to close this now since it’s a bit dated and represents a former issue that’s no longer being discussed.@tbo The correct line for the
package.json
file isFor the version number, just use whatever version your graphql dependency is; mine had the leading caret. In the case of yarn, you will know it worked correctly if the
node_modules/apollo/node_modules
folder does NOT have agraphql
folder in it. If it does, remove yournode_modules
and reinstall your dependencies.@basicdays did you create a new issue?
For people landing here from a google search these are the steps to fix right now:
yarn why graphql
to see the version apollo currently wants (for me it was14.4.2
)"graphql": "~14.4.2",
yarn
Yup, after updating the packages I ran into this error yet again. Setting
graphql
dependency to~14.2.1
fixed it. Should this get switched to a peer dependency in these packages so that npm can at least warn if these tools aren’t sharing the same graphql package instance? I’m also guessing this is probably best if this was made into a new issue.Thanks for unpinning graphql in #1010 The issue described above has been resolved in
apollo@2.5.0
😃In order to remove the oddly pinned dependencies in the Apollo CLI, and apparently another Apollo package, I resorted to using the following to nuking them all after an npm install occurs:
This will find any package named
graphql
in node_modules that is notnode_modules/graphql
ornode_modules/@types/graphql
and remove them.For those using npm or yarn users who don’t want to use resolutions, the following addition to your package.json scripts section can automate this for you. Please note, this is not something to use if this is a distributed library, but is fine to use (imo) if this is just an application.
“graphql”: “~14.0.2”
Using resolutions doesn’t work for me, have to manually remove
graphql
fromnode_modules/apollo/node_modules
to get it workingDoesn’t work for me either
Very likely related to #577, which was fixed in #624. Assuming this is not generally available yet.
For a short-term fix, place this in your
package.json
(thanks @stnwk):@Dremora in my case, I attempted with the same version locally and globally, and met the same result.
Failed on my local project (installed via Yarn) Worked when run from a global install (installed via npm)