【发布时间】:2020-06-28 09:35:13
【问题描述】:
我正致力于在我正在从事的 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
});
}
它在抱怨
类型文件的引用部分是
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