Using "apollo-server-testing": "^2.9.4", as a dependency in our project for graphql testing. When i try to build our Typescript project get the following error
node_modules/apollo-server-testing/node_modules/apollo-cache-control/dist/index.d.ts:24:9 - error TS2717: Subsequent property declarations must have the same type. Property 'cacheControl' must be of type '{ setCacheHint: (hint: CacheHint) => void; cacheHint: CacheHint; }', but here has type '{ setCacheHint: (hint: CacheHint) => void; cacheHint: CacheHint; }'.
24 cacheControl: {
~~~~~~~~~~~~
node_modules/apollo-cache-control/dist/index.d.ts:24:9
24 cacheControl: {
~~~~~~~~~~~~
'cacheControl' was also declared here.
both the types seem same to me so not sure what's the issue that TS is having? :/
seems like i have apollo-cache-control twice in my node_modules folder..

was an issue from having two different versions of apollo-cache-control in the dependencies which was causing ts issues.. updated the version of upstream dependencies so they used the same apollo-cache-control versions
What worked for me was to remove node_modules directory and package-lock.json file and reinstall dependencies.
I switched to Yarn for this issue, as Yarn flattens dependencies by default, and NPM doesn't. I had some mismatch between 0.8.8 from apollo-express, and 1.1.x or something from apollo-server-testing.
I faced the same issue while I was working on NestJS and GraphQL. But I fixed it. You can fix it by following these steps.
Remove the following packages (@nestjs/graphql graphql-tools graphql apollo-server-express) by
yarn remove @nestjs/graphql graphql-tools graphql apollo-server-express
Once done install these packages again at the same time using yarn
yarn add @nestjs/graphql graphql-tools graphql apollo-server-express
Note:
If you are using fastify you will do the same steps with fastify instead of express i.e apollo-server-fastify
@mjraadi @umarnaeem432 having the same issue. Didn't help doing that. :( But having only one dependency of it.
@umarnaeem432 that fixed my issue as well, ty
I tried to simply upgrade apollo-cache-control from 0.9.0 to the latest version (0.11.0) but it didn't work.
I had to yarn remove apollo-cache-control and then yarn add apollo-cache-control.
That fixed the issue for me :)
So TypeScript supports module augmentation and interface merging. It claims that:
Non-function members of the interfaces should be unique. If they are not unique, they must be of the same type. The compiler will issue an error if the interfaces both declare a non-function member of the same name, but of different types.
But for some reason it thinks the additions to GraphQLResolveInfo in apollo-cache-control are not "the same type". I'm not sure if this is a TS bug or there's some good reason for this.
When using prereleases of npm modules, it's a lot easier to end up with two versions of a module in your node_modules tree, where your explicit use of the prerelease pulls in a whole subtree of prerelease Apollo Server modules but some other module pulls in a subtree of non-prerelease Apollo Server modules, and then you have two copies of apollo-cache-control and TypeScript gets sad.
I don't feel great about this suggestion, but one thing that does work (if you're pretty sure that the prerelease of apollo-cache-control doesn't actually differ from the released version in an important way — eg if we've only changed comments or README or something else not relevant to your lifestyle) is to add
"baseUrl": ".",
"paths": {
"apollo-cache-control": ["node_modules/apollo-cache-control"]
}
to your app's tsconfig.json. ie, to tell it only to read the top-level ACC module no matter what.
Not a compelling answer but it is working for my own app testing!
Most helpful comment
What worked for me was to remove
node_modulesdirectory andpackage-lock.jsonfile and reinstall dependencies.