如何检查用户是否有权查看或查询内容?我不知道该怎么做.
args?怎么会这样呢?resolve()?看看用户是否有权限并以某种方式消除/更改某些args?例:
如果用户是"访客",他只能看到公开帖子,"管理员"可以看到一切.
const userRole = 'admin'; // Let's say this could be "admin" or "visitor"
const Query = new GraphQLObjectType({
name: 'Query',
fields: () => {
return {
posts: {
type: new GraphQLList(Post),
args: {
id: {
type: GraphQLString
},
title: {
type: GraphQLString
},
content: {
type: GraphQLString
},
status: {
type: GraphQLInt // 0 means "private", 1 means "public"
},
},
// MongoDB / Mongoose magic happens …Run Code Online (Sandbox Code Playgroud)