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

cacheControl type issues #3339

Closed
mahesh-opendoor opened this issue Sep 25, 2019 · 16 comments
Closed

cacheControl type issues #3339

mahesh-opendoor opened this issue Sep 25, 2019 · 16 comments

Comments

@mahesh-opendoor
Copy link

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? :/

@mahesh-opendoor
Copy link
Author

seems like i have apollo-cache-control twice in my node_modules folder..
Screenshot 2019-09-25 11 37 36

@mahesh-opendoor
Copy link
Author

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

@mjraadi
Copy link

mjraadi commented Nov 22, 2019

What worked for me was to remove node_modules directory and package-lock.json file and reinstall dependencies.

@leehambley
Copy link

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.

@umarnaeem432
Copy link

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

@greg-md
Copy link

greg-md commented Mar 18, 2020

@mjraadi @umarnaeem432 having the same issue. Didn't help doing that. :( But having only one dependency of it.

@amille14
Copy link

amille14 commented May 8, 2020

@umarnaeem432 that fixed my issue as well, ty

@imduchy
Copy link

imduchy commented Jun 5, 2020

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

@glasser
Copy link
Member

glasser commented Sep 21, 2020

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!

@glasser
Copy link
Member

glasser commented Jun 22, 2021

As a note, as of Apollo Server 3 this code now lives in apollo-server-core (apollo-cache-control is being left behind in AS2).

(edit: we may be moving it to apollo-server-types next, #5512)

@braydevkin
Copy link

My solution was make update to @nestjs/graphql to 9.0.0-next.2 and apollo-server-express to 3.0.0, cause the NestJS V8 dont work with apollo-server-core 3.0.0 that is a depencie of server-express but work with V2, however in the @nestjs/graphql version 9 , this was resolved, so now do you can to use @nestjs/graphql 9.0.0 with apollo-server-express 3.0.0

@glasser
Copy link
Member

glasser commented Jul 16, 2021

Yep, you want to use the same versions of apollo-server-express and apollo-server-core!

@euanmillar
Copy link

euanmillar commented Aug 24, 2021

My solution was make update to @nestjs/graphql to 9.0.0-next.2 and apollo-server-express to 3.0.0, cause the NestJS V8 dont work with apollo-server-core 3.0.0 that is a depencie of server-express but work with V2, however in the @nestjs/graphql version 9 , this was resolved, so now do you can to use @nestjs/graphql 9.0.0 with apollo-server-express 3.0.0

So, use these commands and everything is OK:

yarn remove @nestjs/graphql graphql-tools graphql apollo-server-express
yarn add @nestjs/graphql@^9 graphql-tools graphql apollo-server-express@^3

@HoJin9622
Copy link

Screen Shot 2021-12-09 at 6 53 20 PM

npm uninstall apollo-server

After running this command, it works perfectly

@serinuntius
Copy link

I faced the same error.

Enviroment

  • @nestjs/graphql: 10.0.8
  • apollo-server-core: 3.10.1

Solution

install apollo-server-plugin-response-cache package.

I honestly don't know why the error is resolved, but I'll share the solution anyway.

@glasser
Copy link
Member

glasser commented Sep 30, 2022

In Apollo Server 4 (which is in Release Candidate now and should have the final release in a week or two) we've completely stopped using the declare module TypeScript feature which should 100% solve this issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests