Spring Integration 图形QL支持

Spring Integration 提供了用于与GraphQL?协议交互的通道适配器。 该实现基于Spring for GraphQL。

您需要将此依赖项包含在项目中:

<dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-graphql</artifactId> <version>6.0.0</version></dependency>GraphQL 出站网关

这是一个扩展,表示出站网关合约,用于执行 GraphQL 或操作并生成其结果。 它需要 的执行,可以静态配置,也可以针对请求消息通过 SpEL 表达式进行配置。 这是可选的,也可以静态配置或通过 SpEL 表达式进行配置。 这也是可选的,用于参数化操作。 它是可选的,用于GraphQL Java库中的操作执行上下文。 可以通过 SpEL 表达式进行配置,默认为请求消息的标头。??GraphQlMessageHandler????AbstractReplyProducingMessageHandler????query????mutation????subscription????org.springframework.graphql.ExecutionGraphQlService????operation????operationName????variablesExpression????locale????executionId????id??

如果请求消息的有效负载是 的实例,则不会在 中执行任何设置操作,并且此类输入按原样用于 。 否则,将使用上述 SpEL 表达式根据请求消息确定 、 和。??ExecutionGraphQlRequest????GraphQlMessageHandler????ExecutionGraphQlService.execute()????operation????operationName????variables????executionId??

是一个反应式流组件,并生成回复作为 . 这样的 a 由输出通道中的框架订阅,或者在输出通道不响应时异步订阅。 有关如何处理 GraphQL 操作结果的文档。??GraphQlMessageHandler????Mono<ExecutionGraphQlResponse>????ExecutionGraphQlService.execute(ExecutionGraphQlRequest)????Mono????ReactiveStreamsSubscribableChannel????AbstractMessageProducingHandler????ExecutionGraphQlResponse??

@BeanGraphQlMessageHandlerSpec graphQlMessageHandlerSpec(ExecutionGraphQlService graphQlService) { return GraphQl.gateway(graphQlService) .operation(“”” query HeroNameAndFriends($episode: Episode) { hero(episode: $episode) { name friends { name } } }”””) .variablesExpression(“{episode:’JEDI’}”);}@BeanIntegrationFlow graphqlQueryMessageHandlerFlow(GraphQlMessageHandler handler) { return IntegrationFlow.from(MessageChannels.flux(“inputChannel”)) .handle(handler) .channel(c -> c.flux(“resultChannel”)) .get();}@BeanExecutionGraphQlService graphQlService(GraphQlSource graphQlSource) { return new DefaultExecutionGraphQlService(graphQlSource);}@BeanGraphQlSource graphQlSource(AnnotatedControllerConfigurer annotatedDataFetcherConfigurer) { return GraphQlSource.builder() .schemaResources(new ClassPathResource(“graphql/test-schema.graphqls”)) .configureRuntimeWiring(annotatedDataFetcherConfigurer) .build();}@BeanAnnotatedControllerConfigurer annotatedDataFetcherConfigurer() { return new AnnotatedControllerConfigurer();}

应针对订阅操作的结果应用特殊处理。 在这种情况下,返回必须手动订阅和处理的返回。 或者,可以通过普通服务激活器将其平面映射到以下回复:??RequestOutput.getData()????SubscriptionPublisher????FluxMessageChannel??

@ServiceActivator(inputChannel = “graphQlResultChannel”, outputChannel=”graphQlSubscriptionChannel”)public SubscriptionPublisher obtainSubscriptionResult(RequestOutput output) { return output.getData(0);}

这样的出站网关不仅可以用于通过 HTTP 的 GraphQL 请求,还可以用于生成或携带 GraphQL 操作或其在消息中的参数的任何上游端点。 处理结果可以生成为对上游请求的回复,也可以发送到下游以在集成流中进行进一步处理。??GraphQlMessageHandler??

人若勇敢就是自己最好的朋友

Spring Integration 图形QL支持

相关文章:

你感兴趣的文章:

标签云: