如何使用Apollo Gateway和swagger to graphql工具?
我正在通过Swagger到graphql npm模块使用Swagger Petstore,并能够为此运行graphql游乐场如何使用Apollo Gateway和swagger to graphql工具?,graphql,apollo-client,apollo-server,apollo-gateway,Graphql,Apollo Client,Apollo Server,Apollo Gateway,我正在通过Swagger到graphql npm模块使用Swagger Petstore,并能够为此运行graphql游乐场 graphQLSchema('./swagger.json', 'http://petstore.swagger.io/v2', { Authorization: 'Basic YWRkOmJhc2ljQXV0aA==' }).then(schema => { const app = express(); app.use('/', graphqlHTTP
graphQLSchema('./swagger.json', 'http://petstore.swagger.io/v2', {
Authorization: 'Basic YWRkOmJhc2ljQXV0aA=='
}).then(schema => {
const app = express();
app.use('/', graphqlHTTP(() => {
return {
schema,
graphiql: true
};
}));
app.listen(4001, 'localhost', () => {
console.info('http://localhost:4001/');
});
}).catch(e => {
console.log(e);
});
然而,当我试图将服务提供给Apollo网关时,它抛出了一个错误:Apollo服务器需要一个现有的模式或typedef
const gateway=新网关{
服务列表:[
{名称:'pet',url:'http://localhost:4001' }
],
};
const server=新服务器{
网关,
//目前,阿波罗服务器默认启用订阅,
//订阅与网关不兼容。我们希望解决此问题
//阿波罗服务器未来版本的限制。请联系我们
// https://spectrum.chat/apollo/apollo-server 如果这对您的采用至关重要!
订阅:false,
};
然后{url}=>{
console.log`来自:
将现有模式转换为联邦服务是构建联邦图的第一步。为此,我们将使用@apollo/federation包中的buildFederatedSchema函数
您不能仅向网关提供任何现有服务-该服务必须满足。当前唯一的方法是使用buildFederatedSchema创建服务的架构。此时,buildFederatedSchema不兼容任何其他为您生成架构的工具。希望该功能将添加到在不久的将来