我正致力于在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"
}
}任何线索都非常感谢!
发布于 2020-04-30 11:24:43
使用cross-fetch可以解决这个问题。
https://stackoverflow.com/questions/60720099
复制相似问题