这对每个人来说可能都是新的,但希望最好的找到解决方案。
我一直在尝试通过 ApolloGateway 设置阿波罗管理的联盟,以便按照官方文档来联合我的服务。https://www.apollographql.com/docs/graph-manager/managed-federation/setup/#4-deploy-the-modified-gateway
.env
NODE_ENV=development
APOLLO_KEY=service:service_name:hash
阿波罗网关
import 'reflect-metadata';
import express from 'express';
import {ApolloServer} from 'apollo-server-express';
import {ApolloGateway} from '@apollo/gateway';
import {config} from 'dotenv';
config();
const port = process.env.NODE_PORT || 7000;
const nodeEnv = process.env.NODE_ENV || 'localhost';
const nodeHost = process.env.NODE_HOST || 'http://localhost';
const apolloGatewayConfig: any = {
__exposeQueryPlanExperimental: false,
};
if (nodeEnv === 'localhost' || true) {
apolloGatewayConfig.serviceList = [
{
name: 'vendors',
url: `${process.env.GMS_VENDORS_NODE_HOST}/graphql`,
}
];
}
const gateway = new ApolloGateway(apolloGatewayConfig);
(async () => {
const app = express();
app.get('/health', (_, res: any): void => {
res.send({gateway: true});
});
const {schema, executor} = await gateway.load(); // breaking point
const server = new ApolloServer({
schema,
executor,
engine: true,
subscriptions: false,
});
server.applyMiddleware({app, path: '/graphql'});
app.listen({port}, () =>
console.log(`API Gateway is ready at ${nodeHost}:${port}`)
);
})();
在行const {schema, executor} = await gateway.load();
它抛出一个错误
UnhandledPromiseRejectionWarning: Error: When
服务清单is not set, an Apollo Engine configuration must be provided.
我一直在关注官方文档,但不确定我在这里遗漏了什么?