繁体   English   中英

节点获取的 TypeScript、Apollo GraphQL 产量不可分配”错误

[英]TypeScript, Apollo GraphQL yield not assignable" error for node-fetch

我正在我正在处理的 NodeJS/Apollo/GraphQL 项目中实现模式拼接 它是用 TypeScript 编写的。

代码是

import {
    makeRemoteExecutableSchema,
    introspectSchema,
    mergeSchemas
} from 'graphql-tools';
import { HttpLink } from 'apollo-link-http';
import fetch from 'node-fetch';


export default  async () => {
    const link = new HttpLink({
        uri:'http://localhost:4545',
        fetch
    })
    const remoteSchema = await introspectSchema(link);
    // Make remote executable schema
    return makeRemoteExecutableSchema({
        schema: remoteSchema,
        link
    });

}

它抱怨说

在此处输入图片说明 .

类型文件的引用部分是

export interface HttpOptions {
    uri?: string | UriFunction;
    includeExtensions?: boolean;
    fetch?: WindowOrWorkerGlobalScope['fetch'];
    headers?: any;
    credentials?: string;
    fetchOptions?: any;
}

这似乎是一个已修复错误,但在这里似乎没有修复,尽管我使用的是最新版本和线路

fetch?: WindowOrWorkerGlobalScope['fetch'];

似乎确实是推荐用于其中一种解决方法的方法,因此,应该修复它。

对于它的价值,我的package.json

{
  "dependencies": {

    "apollo-datasource-graphql": "^1.3.2",
    "apollo-datasource-rest": "^0.7.0",
    "apollo-link-http": "^1.5.16",
    "apollo-server": "^2.10.1",
    "axios": "^0.19.2",
    "dotenv": "^8.2.0",
    "graphql": "^14.6.0",
    "graphql-tools": "^4.0.7",
    "https-proxy-agent": "^5.0.0",
    "node-fetch": "^2.6.0",
    "uuid": "^7.0.1"
  },
  "devDependencies": {
    "@types/node": "^13.9.1",
    "@types/ramda": "^0.26.43",
    "babel-eslint": "^10.0.3",
    "eslint": "^6.8.0",
    "eslint-config-airbnb-base": "^14.0.0",
    "eslint-config-prettier": "^6.10.0",
    "eslint-plugin-prettier": "^3.1.2",
    "pino": "^5.16.0",
    "prettier": "^1.19.1",
    "ramda": "^0.26.1",
    "typescript": "^3.8.3"
  },
  "scripts": {
    "dev": "tsc && node dist/index.js"
  }
}

任何线索非常感谢!

使用交叉获取将解决这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM