【发布时间】:2021-12-01 21:05:45
【问题描述】:
我正在使用graphql-shield 来保护subgraph。
const isAuthenticated = rule({ cache: 'contextual' })(async (parent, args, ctx, info) => {
return ctx.isAuthenticated
})
const permissions = shield({
Query: {
'*': and(isAuthenticated)
},
Mutation: {
'*': and(isAuthenticated)
}
})
const server = new ApolloServer({
schema: applyMiddleware(buildSubgraphSchema([{ typeDefs, resolvers }]), permissions),
introspection: global.configuration.ENVIRONMENT === 'development'
})
在我的构建过程中,我使用rover CLI 来更新 Apollo Studio 中的supergraph schema:
rover subgraph introspect http://localhost/graphql | rover subgraph publish super-graph@development --routing-url http://localhost/graphql --schema - --name persons
rover 更新失败,因为权限盾引发了 Not Authorised! 错误。
如何使用graphql-shield 保护subgraph 并允许SubgraphIntrospectQuery 操作?
我了解可以向流动站自省命令添加不记名令牌:
rover subgraph introspect http://localhost/graphql --header "Authorization: Bearer token"
但是,我无法在构建过程中生成访问令牌。
【问题讨论】:
标签: node.js graphql graphql-federation graphql-shield