可能是以下原因导致的。请检查:
以下是一些可能有用的代码示例:
const { ApolloGateway } = require("@apollo/gateway");
const { ApolloServer } = require("apollo-server-express");
const express = require("express");
const app = express();
// 连接到GraphQL Express服务
const gateway = new ApolloGateway({
serviceList: [
{ name: "users", url: "http://localhost:4001/graphql" },
{ name: "posts", url: "http://localhost:4002/graphql" }
],
});
// 创建GraphQL服务器
const server = new ApolloServer({
gateway,
subscriptions: false,
});
// 应用GraphQL中间件
server.applyMiddleware({ app });
// 启动Express服务器
app.listen({ port: 4000 }, () => {
console.log(`Server ready at http://localhost:4000${server.graphqlPath}`);
});