Skip to content

ReactiveX java library in order to use GraphQL Subscription with RxJava2 on WebSocket based on Apollo Protocol.

License

Notifications You must be signed in to change notification settings

billybichon/rxLiveGQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

rxLiveGQL

Platform Technology Technology License

ReactiveX java library in order to use GraphQL Subscription with RxJava2 on WebSocket based on Apollo Protocol.

Features

  • connect to a GraphQL server
  • Handle init payload
  • Subscribe/Unsubscribe which return Observables
  • Close connection
  • Error handling (partial)
  • Encoders / Decoders (generic objects)

Requirements

jdk version >= 1.8

How to install

Gradle

dependency {
  compile 'com.github.billybichon:rx-livegql:1.0'
}

maven

<dependency>
  <groupId>com.github.billybichon</groupId>
  <artifactId>rx-livegql</artifactId>
  <version>1.0</version>
</dependency>

manually

Just copy the rx-livegql-1.0.jar inside your libs folder and be sure to use:

dependency {
  compile fileTree(dir: 'libs', include: ['*.jar'])
}

How to use

Connection
RxLiveGQL rxliveGQL = new RxLiveGQL();

rxLiveGQl.connect("ws://your.url").subscribe((str) -> {
  // successfully connect to the server on the first next
}, throwable -> {
  // an error occurred while connecting with the server
}, () -> {
  // on complete, the connection is successfully closed
});

Initialization

rxliveGQL.initServer().subscribe(() -> {
  // successfully initialize the connection with the server
}, throwable -> {
  // an error occurred while initialize the connection with the server
});
subscription
// subscribe
rxLiveGQL.subscribe("query to subscribe", "tag").subscribe(str -> {
  // str contains the data of the subscription
}, throwable -> {
  // some error occurred or the connection has been closed
});

// Unsubscribe
rxLiveGQL.unsubscribe("tag").subscribe(() -> {
  // successfully unsusbcribe
}, throwable -> {
  // some error occurred
});
subscription with generic object
// subscribe
rxLiveGQL.subscribe("query to subscribe", "tag", Obj.Decoder.class).subscribe(obj -> {
  // obj contains the data of the subscription transform into an object by the decoder
}, throwable -> {
  // some error occurred or the connection has been closed
});

// Unsubscribe
rxLiveGQL.unsubscribe("tag").subscribe(() -> {
  // successfully unsubscribe
}, throwable -> {
  // some error occurred
});
close connection
rxLiveGQL.closeConnection().subscribe(() -> {
  // successfully close connection
}, throwable -> {
  // some error occurred
});

Dependency

Libraries on which liveGQL depends:

  • RxJava used to implement ReactiveX design
  • Tyrus for managing websocket
  • Gson for handling json object

Bugs

  • Not sure all errors are catched.

About

ReactiveX java library in order to use GraphQL Subscription with RxJava2 on WebSocket based on Apollo Protocol.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages