GraphQL Java向REST端点发送HTTP头
我需要一种从grapqh java impl向rest端点发送http头以进行身份验证和授权的方法。我正在GraphQL服务层进行身份验证和授权,它是成功的。现在,我需要将相同的头传递给所有rest端点。我有没有办法做到这一点。 Grapqhl-弹簧靴GraphQL Java向REST端点发送HTTP头,java,rest,spring-boot,dropwizard,graphql-java,Java,Rest,Spring Boot,Dropwizard,Graphql Java,我需要一种从grapqh java impl向rest端点发送http头以进行身份验证和授权的方法。我正在GraphQL服务层进行身份验证和授权,它是成功的。现在,我需要将相同的头传递给所有rest端点。我有没有办法做到这一点。 Grapqhl-弹簧靴 Rest端点-Dropwizard执行查询时,可能只是将所需的特定于用户的数据附加到GraphQL上下文,例如: graphQL.execute(queryString, context); 其中上下文可以是任何对象,包含令牌、cookie、会
Rest端点-Dropwizard执行查询时,可能只是将所需的特定于用户的数据附加到GraphQL上下文,例如:
graphQL.execute(queryString, context);
其中上下文可以是任何对象,包含令牌、cookie、会话数据、HttpServletRequest等
然后,使用它从数据获取程序a.k.a.解析程序发送正确的头:
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风格在一个位置执行此头准备逻辑