【问题标题】:Passing arguments from root to sub-query in GraphQL在 GraphQL 中将参数从根传递到子查询
【发布时间】:2019-04-13 15:25:04
【问题描述】:

我正在向我的根查询发送一个参数 (companyId)。我有一个解析器,其中查询不需要此参数,但子查询需要。我有这个函数,我将数据添加到 dataValues 然后尝试返回它,但这不起作用但似乎应该。如果我打印出问题,我会在那里看到 companyId,但它不会作为结果传递给我的 QuestionType 以供后续显示。

questions: {
      type: new GraphQLList(QuestionType),
      args: {
        companyId: {
          type: GraphQLInt
        }
      },
      resolve(parent, args) {
        return connection.models.question.findAll({
          order: [ ['questionCategoryId', 'ASC'], ['orderPlacement', 'ASC']]
        }).then((questions) => {
          for (var i = 0; i < questions.length; i++) {
            questions[i].dataValues.companyId = parseInt(args.companyId)
          }
          return questions
        })
      }
    }

有没有更好的方法将参数从根查询传递到后续查询,其中参数不在根级别使用?

【问题讨论】:

    标签: javascript sequelize.js graphql


    【解决方案1】:

    下班后...这工作我只需要添加一个解析器并返回 parent.dataValues.companyId

    【讨论】:

      猜你喜欢
      • 2018-02-16
      • 1970-01-01
      • 2017-09-27
      • 2023-01-26
      • 1970-01-01
      • 2018-11-27
      • 2021-06-07
      • 1970-01-01
      • 2018-03-08
      相关资源
      最近更新 更多