Spring boot 执行 GraphQL通过 AbstractGraphQLHttpServlet 执行的
GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryType) .build(); ExecutionInput executionInput = ExecutionInput.newExecutionInput().query("query { hero { name } }") .build(); GraphQL graphQL = GraphQL.newGraphQL(schema) .build(); ExecutionResult executionResult = graphQL.execute(executionInput); Object data = executionResult.getData(); List<GraphQLError> errors = executionResult.getErrors();
1. AbstractGraphQLHttpServlet doGet/doPost 标准的servlet
2. HttpRequestHandlerImpl.handle 构建 GraphQLInvocationInput
3. HttpRequestInvokerImpl.execute
4.GraphQLInvoker.executeAsync 构建 GraphQL
5. GraphQL.executeAsync 构建Execution
6. Execution.execute 构建ExecutionStrategy
7.ExecutionStrategy.execute 递归调用每个field,如果有子field,会递归调用,并返回每个field的调用结果。
for (String fieldName : fieldNames) { CompletableFuture<FieldValueInfo> future = resolveFieldWithInfo(executionContext, newParameters); }
7.1 构建 DataFetchingEnvironment,查找对应的DataFetcher,调用 dataFetcher的get获取每个field的值。
protected fetchField() { DataFetchingEnvironment environment = newDataFetchingEnvironment(executionContext) .source(parameters.getSource()) .localContext(parameters.getLocalContext()) .arguments(argumentValues) .fieldDefinition(fieldDef) .mergedField(parameters.getField()) .fieldType(fieldType) .executionStepInfo(executionStepInfo) .parentType(parentType) .selectionSet(fieldCollector) .queryDirectives(queryDirectives) .build(); DataFetcher<?> dataFetcher = codeRegistry.getDataFetcher(parentType, fieldDef); Object fetchedValueRaw = dataFetcher.get(environment); }
7.3 完成一次调用,如果时普通的返回类型,则直接跳出,否则 进入 completeValueForObject,递归调用处理孩子的信息
completeValue() { if (result == null) { fieldValue = completeValueForNull(parameters); return FieldValueInfo.newFieldValueInfo(NULL).fieldValue(fieldValue).build(); } else if (isList(fieldType)) { return completeValueForList(executionContext, parameters, result); } else if (isScalar(fieldType)) { fieldValue = completeValueForScalar(executionContext, parameters, (GraphQLScalarType) fieldType, result); return FieldValueInfo.newFieldValueInfo(SCALAR).fieldValue(fieldValue).build(); } else if (isEnum(fieldType)) { fieldValue = completeValueForEnum(executionContext, parameters, (GraphQLEnumType) fieldType, result); return FieldValueInfo.newFieldValueInfo(ENUM).fieldValue(fieldValue).build(); } // when we are here, we have a complex type: Interface, Union or Object // and we must go deeper // GraphQLObjectType resolvedObjectType; try { resolvedObjectType = resolveType(executionContext, parameters, fieldType); fieldValue = completeValueForObject(executionContext, parameters, resolvedObjectType, result); } catch (UnresolvedTypeException ex) { } return FieldValueInfo.newFieldValueInfo(OBJECT).fieldValue(fieldValue).build(); }
7.4 completeValueForObject调用,构建一个新的ExecutionStrategyParameters参数链,并递归调用7.1的流程
protected completeValueForObject() { ExecutionStrategyParameters newParameters = parameters.transform(builder -> builder.executionStepInfo(newExecutionStepInfo) .fields(subFields) .nonNullFieldValidator(nonNullableFieldValidator) .source(result) ); // Calling this from the executionContext to ensure we shift back from mutation strategy to the query strategy. return executionContext.getQueryStrategy().execute(executionContext, newParameters); }
7.5 构建 ExecutionResult 并返回最终的输出值。
相关推荐
源码 sql parser 描述 1.基于 Java8,利用 Antlr4 实现对 sql 的解析并生成解析树 2.基于解析树生成执行计划 3.基于执行计划,对 Java 内存中数据进行操作,对用户透明,并实现部分 sql 执行 4.Java 内存数据为行式...
java执行原始码命令执行库 它是一个库,您可以在其中输入cmd命令并从Java源代码中获取结果值。 测试代码-----
graphql错误 :warning: 不推荐使用该gem,而建议使用graphql gem中的新GraphQL::Execution::Errors 。 查看更多详细信息 。 这个gem为提供了简单的错误处理。强调每个字段的错误处理。 与Rails类似, rescue_from块...
图形保护器 此gem为提供了字段级授权。 内容 用法 定义一个GraphQL模式: # Define a type class PostType < GraphQL :: Schema :: Object field :id , ID , null : false ... use GraphQL :: Execution :: Int
Use asynchronous and batching execution, or write your own custom add-ons to extend Absinthe. Go live with subscriptions, delivering data over websockets on top of Elixir (and Erlang/OTP's) famous ...
解决Java_heap_space问题
GraphQL 解析器: ://graphql.org/learn/execution/ Adobe I/O Runtime:如何编写、部署和获取操作日志 阅读 检查 确保你也习惯了模式自省,以及如何编写和测试 GraphQL 查询 GraphQL 自省: ://graphql.org/learn...
java连接mysql数据库的驱动,里边包含两个版本:5.1.47、8.0.28 也可从以下两个地址免费下载: 1. https://repo1.maven.org/maven2/mysql/mysql-connector-java/ 2. ...
Marven + Jetty + Myeclipse实现java修改实时生效 1、把jrebel.jar放在任意地方(非项目中) 2、在myeclipse中配置 输入jetty:run -X ...4、启动调试,修改java源码,立即生效,不用重启,目的达到。
Manufacturing Execution Systems – MES Dr.-Ing. Jürgen Kletti Springer Berlin Heidelberg PDF 英文版。解释、建构 MES,最后其中一章谈到与SAP 集成,和塑料加工行业MES 应用。 专门谈 MES 的书其实不多,这本...
基于java编程思想(Thinking in java, TIJ)的教学课件,教学设计请见http://blog.csdn.net/Florianjin
C code for Symstra framework , symbolic execution in java
java虚拟机的运行机理的详细介绍 Inside the Java Virtual Machine Bill Venners $39.95 0-07-913248-0 Inside the Java Virtual Machine Acknowledgments Introduction Part One: Java's Architecture 1 ...
Asynchronous Query Execution异步查询
wsdl2java源码springboot-apachecxf-client 本项目演示了如何在Springboot中实现apachecxf客户端,以及如何为客户端调用生成wsdltojava。 Springboot-apachecxf-jaxws 示例 此应用程序展示了如何使用 apachecxf ...
用以解决androidatudio虚拟机因未装haxm而无法运行的情况: 将intelhaxm-android文件放入..sdk\extras\intel\Hardware_Accelerated_Execution_Manager文件下,然后手动运行intelhaxm-android文件。
第1章 Single Threaded Execution——能通过这座桥的,只有一个人 第2章 Immutable——想破坏它也没办法 第3章 Guarded Suspension——要等到我准备好喔 第4章 Balking——不需要的话,就算了吧 第5章 Producer-...
software test automation effective use of test execution 自动化测试
本书浅显易懂的介绍了JAVA线程相关的设计模式,通过程序范例和UML图示来一一解说,书中代码的重要部分加了标注以使读者更加容易理解,再加上图文并茂,对于初学者还是程序设计高手来说,这都是一本学习和认识JAVA...