TypeScript,Apollo GraphQL收益不可分配“,节点获取错误

问题描述 投票:0回答:1

我正在我正在研究的NodeJS / Apollo / GraphQL项目中实现schema stitching。它是用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
    });

}

并且在抱怨

enter image description here

类型文件的引用部分是

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

这似乎是一个bug that has been fixed,但这里似乎并没有解决,尽管我使用的是最新版本和该行

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"
  }
}

任何线索都值得赞赏!

node.js typescript graphql apollo apollo-server
1个回答
0
投票

使用cross-fetch将解决此问题。

© www.soinside.com 2019 - 2024. All rights reserved.