与此 PR 一起介绍:
https://github.com/apollographql/apollo-link/pull/804
ExecutionResult<TData>
在现代打字稿编译器中引发错误。
我的打字稿错误:
../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.
好的,看起来代码仍然在 DefinitiveTyped 上,所以 #804 中引入的代码应该仍然是正确的。
/**
* 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;
}
您需要确保您的 @types/graphql 是最新的。
@syndesis发现他正在使用 10 个月大的 @types/graphql 0.12.6。 https://www.npmjs.com/package/@types/graphql
现在希望看到最低版本要求。
如果需要更新的 graphql 库就足够公平了,由于其他库依赖项,我也可能使用旧版本。
@gaberudy如果你想加入,我们现在正在 #contributing 上聊天
@gaberudy你也在使用 apollo-link-dedup 吗?
导入graphql-tools
包时我遇到了同样的问题😢
您可以使用 package.json 中的resolutions
部分来解决此问题:
"resolutions": {
"apollo-link-dedup": "^1.0.13",
"@types/graphql": "^14.0.0"
}
在解决后关闭它,如果在建议的修复后仍有问题,请随时重新打开。
您可以使用 package.json 中的
resolutions
部分来解决此问题:"resolutions": { "apollo-link-dedup": "^1.0.13", "@types/graphql": "^14.0.0" }
不幸的是,这并没有为我解决问题
这个问题仍然没有解决
升级到最新软件包后,这发生在我身上。 请问这个可以重开吗?
建议的解决方案不起作用,我没有使用 dedup。
我有同样的问题。
我已经尝试过:
还有其他建议吗?
这个问题的任何修复?
@qin-guan,您应该升级您的依赖项,但请确保您还升级了传递依赖项。 最简单的方法是删除 node_modules 和锁定文件,然后重新安装。 如果您不删除锁定文件,您实际上可能会被旧版本卡住(请参阅 https://github.com/yarnpkg/yarn/issues/4986)。
我发现从 15.0.0 -> 14.6.0 降级 graphql 可以解决这个问题。
@ PowerKiKi ,@david-wb 的解决方案对我有用,升级我的部门不起作用
该软件包与最新的graphql: ^15.0.0
版本不同。 关于如何解决后者的任何想法?
@johannesschobel在评论之前尝试阅读。 您现在需要降级。
亲爱的@OmgImAlexis ,
是的,我知道 - 我阅读了有关降级到14.6.0
的“当前解决方法”。 但是,这对我来说是当前的障碍,因为其他软件包已经依赖于15.0
,所以我很卡住..
一切顺利
这个问题真的很糟糕。 怎么还没修好??
刚刚也碰到这个。。。
我解决此问题的唯一方法是将graphql降级为14.6.0
我遇到了这个错误,因为我的项目根目录中有一个用于云功能的functions
目录,它有自己的node_modules
用于客户端。 客户端使用 14 系列,服务器使用 15 系列。
我用patch-package
解决了这个问题
添加一个名为functions/patches/graphql+15.0.0.patch
的文件,其中包含以下内容:
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 = {
然后将npx patch-package
添加到postinstall
该补丁仅影响 ts 类型,因此乍一看似乎是一个安全的解决方案,直到上游解决了问题。
是的,我不得不恢复到
"graphql": "^14.6.0"
从
"graphql": "10.0.0",
让它发挥作用。
@gaberudy我们会看到对此的更新吗? 现在已经开了3个月了。
它也可以被锁定,这样我们就不会不断收到“我不得不恢复”的评论吗?
我还不得不从 15 降级到 14.6.0
这是否可能由https://github.com/apollographql/apollo-link/pull/1263修复,但尚未完全传播到依赖它的包?
亲爱的@abernix ,感谢您指出这一点。 看起来原始问题已得到解决和修复。 但是, apollo-client
没有,现在抛出相同的错误 :laughing:
@OmgImAlexis
我们会看到对此的更新吗? 现在已经开了3个月了。
我想你错过了 2019 年 ;-) 已经一年多了。
以下分辨率和依赖版本为我修复了它 - 最重要的是apollo-link
分辨率为^1.2.14
。 这将强制任何使用 apollo-link 的包使用最新版本(无论它在其依赖项中指定什么)。 对我来说,这是固定到“apollo-link”的aws-appsync
包:“1.2.3”
"resolutions": {
"apollo-link": "^1.2.14"
},
"dependencies": {
"graphql": "^14.6.0",
}
我刚收到这个问题。 也不得不降级。 这样的问题怎么还会出现?
确实.. 降级到[email protected]也为我解决了这个问题。
[email protected] 上的typescript有这个泛型类型问题
@david-wb 感谢降级到 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>>;
~~~~~~~~~~~~~~~~~~~~~~
在降级到"graphql": "^14.6.0"
并执行npm install
后,我遇到了上述错误"graphql": "^15.0.0"
对我有用
这已在https://github.com/apollographql/apollo-client/pull/6258 中得到解决。 如果有人仍然遇到此问题,请尝试更新到[email protected]
。 谢谢!
使用[email protected]对我不起作用
@moritzewert您是否仍然看到ExecutionResult
错误或其他错误? 你能发布运行的输出吗: npx envinfo<strong i="7">@latest</strong> --preset apollo
你好@hwillson ,
在将 graphql 从14.6.0
升级到15.0.0
后,我看到了这个问题。
错误:
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
这是我的环境信息:
$ npx envinfo<strong i="14">@latest</strong> --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
谢谢!
最有用的评论
我发现从 15.0.0 -> 14.6.0 降级 graphql 可以解决这个问题。