在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):graphql-java/graphql-java-subscription-example开源软件地址(OpenSource Url):https://github.com/graphql-java/graphql-java-subscription-example开源编程语言(OpenSource Language):Java 75.6%开源软件介绍(OpenSource Introduction):graphql-java Subscriptions over WebSockets exampleAn example of using graphql subscriptions via websockets, graphql-java, reactive-streams and RxJava. To build the example code in this repository type:
To run the example code type:
To access the example application, point your browser at:
Code ExplanationThis example shows how you can use graphql-java subscription support to "subscribe" to a publisher of events.
Then as events occur, graphql-java will map the original graphql query over those same event objects and send out
a stream of In this example application we have a stock update type system defined as:
The JavaScript client sends a subscription graphql query over websockets to the server:
The server executes this with the graphql-java engine:
The result of that initial subscription query is a http://www.reactive-streams.org/
Under the covers a RxJava 2.x implementation is used to provide a stream of synthesized stock events. Rxjava Flows are an implementation of the reactive streams Publisher interface. You can use ANY reactive streams implementation as a source. graphql-java uses the reactive streams interfaces as a common interface. See https://github.com/ReactiveX/RxJava for more information on RxJava. The server side code then subscribes to this publisher of events and sends the results back over the websocket to the waiting browser client:
The selection set of fields named in the original query will be applied to each underlying stock update object. The selection set in this example application is selected as follows:
The underling stock update object is mapped to this selection of fields, just like any normal graphql query. The format of the results on the browser is JSON, again like any other normal graphql query. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论