相关疑难解决方法(0)

在GraphQL中查看器字段的含义是什么?

viewerGraphQL 中根查询字段的用途是什么?

根据这篇文章,viewer可以用来接受一个令牌参数,这样我们就可以看到当前登录的是谁.

我该如何实施呢?

graphql relayjs

26
推荐指数
1
解决办法
7103
查看次数

如何在GraphQL查询中检查权限和其他条件?

如何检查用户是否有权查看查询内容?我不知道该怎么做.

  • 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)

mongoose node.js graphql

11
推荐指数
2
解决办法
4117
查看次数

标签 统计

graphql ×2

mongoose ×1

node.js ×1

relayjs ×1