Search code examples
graphqlapollo-servertypegraphql

why instaling type-graphql, @apollo/server and graphql together showing dependency error


I have been trying to install typegraphql with apollo/server in typescript node template but it showing dependency error, I don't know why all new version is not compatible with each other.

npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/graphql
npm ERR!   graphql@"*" from the root project
npm ERR!   peer graphql@"^16.6.0" from @apollo/[email protected]
npm ERR!   node_modules/@apollo/server
npm ERR!     @apollo/server@"*" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! type-graphql@"*" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/graphql
npm ERR!   peer graphql@"^15.3.0" from [email protected]
npm ERR!   node_modules/type-graphql
npm ERR!     type-graphql@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.



$ npm i @apollo/server express graphql reflect-metadata type-graphql

should forcing it works or will it lead to data-leaks and all? Thanks in advance for replying


Solution

  • The most recent version of type-graphql only works with graphql version ^15.5.0. Almost all newer versions of @apollo/server and graphql-related libraries, on the other hand, only support graphql version >= 16. Fortunately, a newer version of type-graphql (version 2.0.0), which is still in beta, is available under the next tag version in npm. To install it, first uninstall type-graphql and then reinstall it specifying the next tag:

    npm uninstall type-graphql
    npm install type-graphql@next
    

    PS: If you want to look at a working example project, check out this.