From 911edc909c47066e14ff67e5b72f07b218e43744 Mon Sep 17 00:00:00 2001 From: dialYun <1552333077@qq.com> Date: Sun, 27 Oct 2024 09:39:43 +0000 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=9C=A8ServiceContext?= =?UTF-8?q?=E4=B8=AD=E8=AE=BE=E7=BD=AE=E5=B9=B6=E4=BD=BF=E7=94=A8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=9D=83=E9=99=90=E5=A4=84=E7=90=86=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dialYun <1552333077@qq.com> --- .../java/io/nop/biz/service/BizActionInvoker.java | 8 ++++---- .../graphql/core/IGraphQLExecutionContext.java | 4 ++++ .../io/nop/graphql/core/engine/GraphQLEngine.java | 15 +++++++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/nop-biz/src/main/java/io/nop/biz/service/BizActionInvoker.java b/nop-biz/src/main/java/io/nop/biz/service/BizActionInvoker.java index bce39a4e2..2fdf3f219 100644 --- a/nop-biz/src/main/java/io/nop/biz/service/BizActionInvoker.java +++ b/nop-biz/src/main/java/io/nop/biz/service/BizActionInvoker.java @@ -84,18 +84,18 @@ public static CompletionStage invokeActionAsync(String bizObjName, Strin * @return 结果对象 */ public static CompletionStage> invokeGraphQLAsync(String bizObjName, String bizAction, - ApiRequest request) { + ApiRequest request, IServiceContext context) { IGraphQLEngine graphQLEngine = BeanContainer.getBeanByType(IGraphQLEngine.class); String realBizName = bizObjName + "__" + bizAction; - IGraphQLExecutionContext gqlCtx = graphQLEngine.newRpcContext(null, realBizName, request); + IGraphQLExecutionContext gqlCtx = graphQLEngine.newRpcContext(null, realBizName, request, context); return graphQLEngine.executeRpcAsync(gqlCtx); } public static ApiResponse invokeGraphQLSync(String bizObjName, String bizAction, - ApiRequest request) { + ApiRequest request, IServiceContext context) { IGraphQLEngine graphQLEngine = BeanContainer.getBeanByType(IGraphQLEngine.class); String realBizName = bizObjName + "__" + bizAction; - IGraphQLExecutionContext gqlCtx = graphQLEngine.newRpcContext(null, realBizName, request); + IGraphQLExecutionContext gqlCtx = graphQLEngine.newRpcContext(null, realBizName, request, context); return graphQLEngine.executeRpc(gqlCtx); } } diff --git a/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/IGraphQLExecutionContext.java b/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/IGraphQLExecutionContext.java index cec746e39..f6257a150 100644 --- a/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/IGraphQLExecutionContext.java +++ b/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/IGraphQLExecutionContext.java @@ -126,6 +126,10 @@ default IActionAuthChecker getActionAuthChecker(){ return getServiceContext().getActionAuthChecker(); } + default IDataAuthChecker getDataAuthChecker(){ + return getServiceContext().getDataAuthChecker(); + } + default IUserContext getUserContext(){ return getServiceContext().getUserContext(); } diff --git a/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/engine/GraphQLEngine.java b/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/engine/GraphQLEngine.java index b9885b7b1..12a4ce5dd 100644 --- a/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/engine/GraphQLEngine.java +++ b/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/engine/GraphQLEngine.java @@ -318,10 +318,17 @@ public GraphQLFieldDefinition getOperationDefinition(GraphQLOperationType opType public IGraphQLExecutionContext newGraphQLContextFromContext(IServiceContext ctx) { GraphQLExecutionContext context = new GraphQLExecutionContext(ctx); - if (enableActionAuth) - context.setActionAuthChecker(actionAuthChecker); - if (enableDataAuth) - context.setDataAuthChecker(dataAuthChecker); + if (enableActionAuth){ + if (context.getActionAuthChecker() == null){ + context.setActionAuthChecker(actionAuthChecker); + } + } + + if (enableDataAuth){ + if (context.getDataAuthChecker() == null){ + context.setDataAuthChecker(dataAuthChecker); + } + } return context; }