概述
如何落地应用(Application concerns)
graphql-java 引擎主要的关注点是按 GraphQL 规范来执行查询。
它本身不关注应用的其它方面,如:
数据库访问
缓存数据
数据权限控制
数据分页
HTTP 转换
JSON 编码
依赖注入的编程方法
你需要在自己的业务逻辑层中实现这些。
下面是一些相关方案的介绍:
上下文对象(Context Objects)
为更方便的业务调用,你可以在查询执行中加入Context Object。
例如,你的应用的边界模块可能会做用户识别,然后 GraphQL
查询执行时,你可以想做数据权限控制。
下面例子演示怎么向你的查询传递信息:
//
// this could be code that authorises the user in some way and sets up enough context
// that can be used later inside data fetchers allowing them
// to do their job
//
UserContext contextForUser = YourGraphqlContextBuilder.getContextForUser(getCurrentUser());
ExecutionInput executionInput = ExecutionInput.newExecutionInput()
.context(contextForUser)
.build();
ExecutionResult executionResult = graphQL.execute(executionInput);
// ...
//
// later you are able to use this context object when a data fetcher is invoked
//
DataFetcher dataFetcher = new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment environment) {
UserContext userCtx = environment.getContext();
Long businessObjId = environment.getArgument("businessObjId");
return invokeBusinessLayerMethod(userCtx, businessObjId);
}
};
最后
以上就是潇洒小馒头为你收集整理的graphql java如何使用_graphql-java使用手册:part10 如何落地应用(Application concerns)...的全部内容,希望文章能够帮你解决graphql java如何使用_graphql-java使用手册:part10 如何落地应用(Application concerns)...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复