apollo-link 1.2.5 / 1.2.6 causes typescript compile errors

Created on 16 Jan 2019  ·  39Comments  ·  Source: apollographql/apollo-link

Introduced with this PR:
https://github.com/apollographql/apollo-link/pull/804

The ExecutionResult<TData> throws errors in modern typescript compilers.

My typescript error:

../node_modules/apollo-link/lib/types.d.ts:22:56 - error TS2315: Type 'ExecutionResult' is not generic.

22 }, C = Record<string, any>, E = Record<string, any>> = ExecutionResult<TData> & {
                                                          ~~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

Most helpful comment

I found that downgrading graphql from 15.0.0 -> 14.6.0 resolves the issue.

All 39 comments

Ok, looks like the code is still on DefinitelyTyped, so the code introduced in #804 should still be correct.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/graphql/execution/execute.d.ts#L43

/**
 * The result of GraphQL execution.
 *
 *   - `errors` is included when any errors occurred as a non-empty array.
 *   - `data` is the result of a successful execution of the query.
 */
export interface ExecutionResult<TData = ExecutionResultDataDefault> {
    errors?: ReadonlyArray<GraphQLError>;
    data?: TData;
}

You will need to make sure your @types/graphql are up to date.

@syndesis found he was using @types/graphql 0.12.6 which is 10 month old. https://www.npmjs.com/package/@types/graphql

Looking to see the min version requirement now.

Fair enough if newer graphql lib is needed, I also may be on an older version due to other library dependencies.

@gaberudy we are chatting in #contributing right now on slack if you want to join

@gaberudy are you also using apollo-link-dedup?

I have this same issue when importing graphql-tools package 😢

You can work around this issue with a resolutions section like this in your package.json:

"resolutions": {
    "apollo-link-dedup": "^1.0.13",
    "@types/graphql": "^14.0.0"
  }

Closing this since it is resolved, if anyone still has an issue after the proposed fix with resolutions feel free to reopen.

You can work around this issue with a resolutions section like this in your package.json:

"resolutions": {
    "apollo-link-dedup": "^1.0.13",
    "@types/graphql": "^14.0.0"
  }

Unfortunately, this did not fix the problem for me

this issue still didn't resolved

This is happening for me after upgrading to the latest packages. Can we get this reopened please?

The proposed resolution does not work, and I'm not using dedup.

I have the same issue.

I've already tried:

  • resolution solution.
  • upgrading apollo & graphql

any other suggestions?

any fixes for this issue?

@qin-guan you should upgrade your dependencies, but be sure you also upgrade transitive dependencies. The easiest way to do that is to remove node_modules and the lock file, then install again. If you don't remove the lock file you might actually get stuck with an old version (see https://github.com/yarnpkg/yarn/issues/4986).

I found that downgrading graphql from 15.0.0 -> 14.6.0 resolves the issue.

@PowerKiKi, @david-wb's solution works for me, upgrading my deps did not work

This package breaks with the latest graphql: ^15.0.0 version. Any ideas on how to fix the latter?

@johannesschobel try and read before commenting. You’ll need to downgrade for now.

Dear @OmgImAlexis ,
yeah, i know - and i read the "current workaround" regarding downgrading to 14.6.0. However, this is a current roadblock for me, as other packages already depend on 15.0, so i am quite stuck..

All the best

This issue is REALLY bad. How is it still not fixed??

Just ran into this as well...

Only way for me to workaround this was downgrading graphql to 14.6.0

I encountered this error because I have a functions dir for cloud functions inside my project root, which has it's own node_modules for client. Client is using 14 series, and server is using 15 series.

I solved the problem with patch-package

add a file called functions/patches/graphql+15.0.0.patch with this content:

diff --git a/node_modules/graphql/execution/execute.d.ts b/node_modules/graphql/execution/execute.d.ts
index 46a1bc6..4ddbfb5 100644
--- a/node_modules/graphql/execution/execute.d.ts
+++ b/node_modules/graphql/execution/execute.d.ts
@@ -37,15 +37,20 @@ export interface ExecutionContext {
   errors: Array<GraphQLError>;
 }

+export interface ExecutionResultDataDefault {
+  [key: string]: any;
+}
+
 /**
  * The result of GraphQL execution.
  *
  *   - `errors` is included when any errors occurred as a non-empty array.
  *   - `data` is the result of a successful execution of the query.
  */
-export interface ExecutionResult {
+// TS_SPECIFIC: TData and ExecutionResultDataDefault
+export interface ExecutionResult<TData = ExecutionResultDataDefault> {
   errors?: ReadonlyArray<GraphQLError>;
-  data?: { [key: string]: any } | null;
+  data?: TData | null;
 }

 export type ExecutionArgs = {

then add npx patch-package to postinstall

the patch only affects ts typings so it seems at first blush to be a safe solution until upstream solves the problem.

Yes, I had to revert back to

"graphql": "^14.6.0"

From

"graphql": "10.0.0",

To get this to work.

@gaberudy are we ever going to see an update to this? It's been open now for 3 months.

Also can it be locked so we don't keep getting "I had to revert" comments?

I also had to downgrade from 15 to 14.6.0

Was this possibly fixed by https://github.com/apollographql/apollo-link/pull/1263 but not fully propagated out to packages which depend on it yet?

Dear @abernix , thanks for pointing this out. Looks like the original issue has been addressed and fixed. However, apollo-client has not and now throws the same errors :laughing:

@OmgImAlexis

are we ever going to see an update to this? It's been open now for 3 months.

I think you missed the year 2019 ;-) It's been over a year already.

The below resolutions & dependency versions fixed it for me - most importantly the apollo-link resolution to ^1.2.14. This will force any package using apollo-link to use the latest version (regardless of what it specifies in its dependencies). For me it was the aws-appsync package pinned to "apollo-link": "1.2.3"

  "resolutions": {
    "apollo-link": "^1.2.14"
  },
  "dependencies": {
    "graphql": "^14.6.0",
  }

I just got this issue. Had to downgrade too. How can such an issue still be here?

Indeed.. downgrading to [email protected] fixed the issue for me too.

Having this generic type issue with typescript on [email protected]

@david-wb thanks working fine after downgrade to 14.6.0

ERROR in node_modules/apollo-client/core/watchQueryOptions.d.ts:56:32 - error TS2315: Type 'ExecutionResult' is not generic.       

56     refetchQueries?: ((result: ExecutionResult<T>) => RefetchQueryDescription) | RefetchQueryDescription;
                                  ~~~~~~~~~~~~~~~~~~
node_modules/apollo-client/core/LocalState.d.ts:40:23 - error TS2315: Type 'ExecutionResult' is not generic.

40         remoteResult: ExecutionResult<TData>;
                         ~~~~~~~~~~~~~~~~~~~~~~
node_modules/apollo-client/core/LocalState.d.ts:44:17 - error TS2315: Type 'ExecutionResult' is not generic.

44     }): Promise<ExecutionResult<TData>>;
                   ~~~~~~~~~~~~~~~~~~~~~~

I had the above error with "graphql": "^15.0.0", after downgrading to "graphql": "^14.6.0" and doing npm install worked for me

This has been addressed in https://github.com/apollographql/apollo-client/pull/6258. If anyone is still encountering this issue, please try updating to [email protected]. Thanks!

using [email protected] didn't work for me

@moritzewert are you still seeing ExecutionResult errors or something else? Can you post the output of running: npx envinfo@latest --preset apollo

Hello @hwillson ,
I am seeing this issue after upgrading graphql from 14.6.0 to 15.0.0.
The error:

Type 'ExecutionResult' is not generic.
    21 | export declare type FetchResult<TData = {
    22 |     [key: string]: any;
  > 23 | }, C = Record<string, any>, E = Record<string, any>> = ExecutionResult<TData> & {
       |                                                        ^
    24 |     extensions?: E;
    25 |     context?: C;
    26 | };
Version: typescript 3.9.3

Here is my envinfo:

$ npx envinfo@latest --preset apollo
npx: installed 1 in 1.063s

  System:
    OS: macOS 10.15.4
  Binaries:
    Node: 10.19.0 - ~/.nvm/versions/node/v10.19.0/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.1 - ~/code/frontend/node_modules/.bin/npm
  Browsers:
    Chrome: 83.0.4103.61
    Edge: 83.0.478.44
    Firefox: 76.0.1
    Safari: 13.1
  npmPackages:
    apollo-boost: ^0.4.7 => 0.4.9
    apollo-cache-inmemory: ^1.6.6 => 1.6.6
    apollo-client: ^2.6.10 => 2.6.10
    apollo-codegen: ^0.20.2 => 0.20.2
    apollo-link: ^1.2.14 => 1.2.14
    apollo-link-context: ^1.0.20 => 1.0.20
    apollo-link-http: ^1.5.17 => 1.5.17
    apollo-link-state: ^0.4.2 => 0.4.2
    apollo-link-ws: ^1.0.20 => 1.0.20

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

valerybugakov picture valerybugakov  ·  5Comments

Nickersoft picture Nickersoft  ·  3Comments

ignivalancy picture ignivalancy  ·  5Comments

j3ddesign picture j3ddesign  ·  3Comments

Morantron picture Morantron  ·  3Comments