0

我需要一种从我的 grapqh-java impl 向我的其余端点发送用于身份验证和授权的 http 标头的方法。我在 GraphQL 服务层进行身份验证和授权,并且成功。现在我需要将相同的标头传递给我所有的其余端点。有没有办法我可以做到这一点。Grapqhl - Spring Boot Rest 端点 - Dropwizard

4

1 回答 1

1

也许只是在执行查询时将所需的用户特定数据附加到 GraphQL 上下文,例如:

graphQL.execute(queryString, context);

哪里context可以是任何对象,包含令牌、cookie、会话数据HttpServletRequest

然后,使用它从您DataFetcher的 s(又名解析器)发送正确的标头:

public Object get(DataFetchingEnvironment environment) {
    Map<String, Object> context = environment.getContext();
    //get tokens, session data or whatever you need from the context to create the headers
    List headers = ...;
    return callRestWithHeaders("/rest/example", headers);
}

最好通过组合、继承或 AOP 样式在一个地方执行此标头准备逻辑。

于 2017-09-15T00:11:29.800 回答