跳到主要内容

GraphQL

调用 GraphQL 微服务,可以实现在服务端执行 GrahpQL 查询。

如果查询 GraphQL 需要带上当前用户的权限,需要传入 user 属性。

actions: {
graphqlQuery: {
rest: { method: 'GET', path: '/graphql' },
// 在微服务中查询数据库
async handler(ctx) {
return await this.broker.call('api.graphql', {
query: `
query {
space_users(filters: ["user", "=", "${ctx.meta.user.userId}"]) {
name
organization__expand {
name
}
}
}
`},
// 如果查询 GraphQL 需要带上当前用户的权限,需要传入 user 属性。
{
meta: {
user: ctx.meta.user
}
}
);
},
}
}