【问题标题】:How to pass JTW token (or any other variable) from parent to children resolver with Aws AppSync如何使用 Aws AppSync 将 JWT 令牌(或任何其他变量)从父解析器传递给子解析器
【发布时间】:2019-08-23 11:23:03
【问题描述】:

我正在尝试将 JWT 令牌传递给我在 AppSync 中的嵌套查询,以检查用户是否有权请求此类数据。

问题在于 AppSync 不允许我将 JWT 令牌从父查询转发到任何子解析器

例子:

mutation test {
emailSignIn(input: {email: "0@gmail.com", password: "XYZ"}) {
token
currentUser {
  id
  profilePicture {
    uuid
  }
  ... on Client {
    lastName
    pleadingList{
      id
      pleadingFiles {
        uuid
      }
      pleadingParticipantSlots {
        id
        participant {
          id
        }
      }
    }
  }

}
}
}

这里profilePicturepleadingListpleadingFilespleadingParticipantSlotsparticipant 是子查询,我希望能够识别出谁在执行每个子查询,而不仅仅是主查询/父查询

有什么解决办法吗?

我已经尝试过的:

问题是,当我将令牌动态添加到主结果时,它并不总是有效(从某种意义上说,如果我从查询中返回的是一个 Item 数组,而子查询是每个项目,那么我无法访问每个子请求中的令牌,因为$ctx.source 将只是没有令牌的项目。

  • 我还尝试了将 JWT 令牌添加到 ctx.stash 的管道,但更糟糕的是,ctx.stash(和 ctx.args)在任何子请求之前被清除

所以我想要一种将变量传递给我所有子解析器的方法,或者一种将我的标头从父请求保留到嵌套查询的方法。

我让它工作的唯一方法(它非常难看,我不想这样做;))是每次在前端添加令牌作为查询和子查询参数......

喜欢:

mutation test {
emailSignIn(input: {email: "0@gmail.com", password: "XYZ"}) {
token
currentUser {
  id
  profilePicture(token: "blablabla") {
    uuid
  }
  ... on Client {
    lastName
    pleadingList(token: "blablabla") {
      id
      pleadingFiles(token: "blablabla") {
        uuid
      }
      pleadingParticipantSlots {
        id
        participant(token: "blablabla") {
          id
        }
      }
    }
  }

}
}
}

我有点迷茫,在 AWS AppSync 文档中找不到任何相关内容。 有什么办法吗?还是我想错了?

谢谢

【问题讨论】:

    标签: graphql aws-appsync vtl


    【解决方案1】:

    目前,AppSync 不支持将 JWT 令牌从父解析器传递到子解析器。您提到的解决方法可能是当前选项之一。

    【讨论】:

      猜你喜欢
      • 2019-03-01
      • 2018-12-20
      • 2021-03-21
      • 2020-05-29
      • 2021-01-07
      • 1970-01-01
      • 2021-12-03
      • 2019-11-25
      • 2019-02-04
      相关资源
      最近更新 更多