如何在从联邦graphql网关传递下来的gqlgen子图中获取graphql上下文?
发布于 2022-07-05 21:06:04
您需要在网关中添加一个buildService函数,该函数将网关中的上下文串成字符串,然后将其注入将被发送到子图的标题中,然后在子图中,您将需要解析该标题并将其放入上下文中,以便您的解析能够访问它。就像这样:
{
gateway: {
buildService({ url }) {
return new RemoteGraphQLDataSource({
url,
willSendRequest({ request, context }) {
request.http.headers.set('X-GQL-Context', JSON.stringify(context))
},
})
},
},
}https://stackoverflow.com/questions/72758650
复制相似问题