我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
用来更新supergraph schema
Apollo Studio 中的:
rover subgraph introspect http://localhost/graphql | rover subgraph publish super-graph@development --routing-url http://localhost/graphql --schema - --name persons
更新失败,rover
因为权限屏蔽引发Not Authorised!
错误。
我如何保护subgraph
并graphql-shield
允许SubgraphIntrospectQuery
操作?
我了解可以将承载令牌添加到流动站自省命令:
rover subgraph introspect http://localhost/graphql --header "Authorization: Bearer token"
但是,我无法在构建过程中生成访问令牌。