我正在考虑编写一个执行以下操作的API:
{ name: “Quotes”, attributes: [“quote”, “author"] }){ quote: "...", author: "..." })我会像这样构建查询:
// return the name and id of all the user's maps
maps(authToken="…") {
name,
id
}
// return all the items of a single map
maps(authToken="…") {
map(name=“Quotes") {
items
}
}
// OR by using the map_id
maps(authToken="…") {
map(id=“…") {
items
}
}
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是,这是正确的还是我需要以不同的方式构建它?
如何检查用户是否有权查看或查询内容?我不知道该怎么做.
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)