AppSync作为另一台GraphQl Server的代理
我有第三方为第三方提供的现有GraphQL服务器。我也有自己在EC2上运行的后端以提供API。
我正在尝试使用 aws-cdk 构建AppSync,以连接到第三方GraphQl和我的后端实例。 使用GraphQL Server,AppSync将充当仅转发查询的代理。我的问题是:
无论如何我们是否有加载远程模式并将其填充在AppSync及其模式?
?如何使用AWS-CDK将请求转发到另一台GraphQl Server?我正在尝试这样的事情:
private get _requestMappingTemplate(): string {
return `
{
"version": "2018-05-29",
"method": "GET",
"resourcePath": $util.toJson("/graphql"),
"params": {
"headers": {
"Authorization": "Bearer $ctx.request.headers.Authorization"
},
"body": {
"query": "$util.escapeJavaScript($ctx.info.getSelectionSetGraphQL())"
}
}
}`;
}
但是从AWS doc > getSelectionsEtgraphql 返回选择集的字符串表示,格式为GraphQl Schema定义语言(SDL)。尽管没有将片段合并到选择集中,
是否可以设置AppSync以将请求转发到另一个GraphQl服务器?有什么最佳做法要遵循吗?
I have a existing graphql server provied by 3rd party. I also have my own backend running on EC2 to provide APIs.
I'm trying to build the appsync with aws-cdk for connecting to both 3rd party graphql and my backend instance also.
With the graphql server, appsync will act as proxy to forward queries only. My questions are:
Do we have anyway to load remote schema and populate it in appsync along with its schema?
How can we forward the requests to another graphql server using aws-cdk? I'm trying something like this:
private get _requestMappingTemplate(): string {
return `
{
"version": "2018-05-29",
"method": "GET",
"resourcePath": $util.toJson("/graphql"),
"params": {
"headers": {
"Authorization": "Bearer $ctx.request.headers.Authorization"
},
"body": {
"query": "$util.escapeJavaScript($ctx.info.getSelectionSetGraphQL())"
}
}
}`;
}
But from the aws doc, getSelectionSetGraphQL returns string representation of the selection set, formatted as GraphQL schema definition language (SDL). Although fragments aren't merged into the selection set
Is that possible to setup AppSync for forwarding request to another GraphQL servers? Any best practice to follow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这要复杂得多。我仍在努力,到目前为止,我得到的最好的东西在下面给出。它仍然会删除查询参数,因此使用有限。
It's quite a bit more complicated. I'm still working on it, and the best I got so far is given below. It still drops query arguments, so has limited use.