Skip to content

Commit

Permalink
update examples, changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
obmarg committed Feb 10, 2024
1 parent d09f7e9 commit 827bec6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 41 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ all APIs might be changed.

## Unreleased - xxxx-xx-xx

### Breaking Changes

- The `next` api is now available at the top level rather than the `next`
module.

### Deprecations

These will be removed in a future version, probably in v0.9.0

- `AsyncWebsocketClient` and all its supporting traits and structs are now
deprecated.

### New Features

- Added a `streaming_operation` function to `next::ClientBuilder` to make
Expand Down
15 changes: 7 additions & 8 deletions examples/examples/mulitiple-subscriptions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! An example of running a multiple subscriptions on a single connection
//! using `graphql-ws-client` and `async-tungstenite`
//! using `graphql-ws-client`, `async-tungstenite` & the `async_std`
//! executor.
//!
//! Talks to the the tide subscription example in `async-graphql`

use std::future::IntoFuture;

mod schema {
cynic::use_schema!("../schemas/books.graphql");
}
Expand Down Expand Up @@ -38,7 +41,7 @@ struct BooksChangedSubscription {
async fn main() {
use async_tungstenite::tungstenite::{client::IntoClientRequest, http::HeaderValue};
use futures::StreamExt;
use graphql_ws_client::CynicClientBuilder;
use graphql_ws_client::Client;

let mut request = "ws://localhost:8000/graphql".into_client_request().unwrap();
request.headers_mut().insert(
Expand All @@ -52,12 +55,8 @@ async fn main() {

println!("Connected");

let (sink, stream) = connection.split();

let mut client = CynicClientBuilder::new()
.build(stream, sink, async_executors::AsyncStd)
.await
.unwrap();
let (mut client, actor) = Client::build(connection).await.unwrap();
async_std::task::spawn(actor.into_future());

// In reality you'd probably want to different subscriptions, but for the sake of this example
// these are the same subscriptions
Expand Down
12 changes: 4 additions & 8 deletions examples/examples/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//!
//! Talks to the the tide subscription example in `async-graphql`

use examples::TokioSpawner;
use std::future::IntoFuture;

mod schema {
cynic::use_schema!("../schemas/books.graphql");
Expand Down Expand Up @@ -40,7 +40,7 @@ struct BooksChangedSubscription {
async fn main() {
use async_tungstenite::tungstenite::{client::IntoClientRequest, http::HeaderValue};
use futures::StreamExt;
use graphql_ws_client::CynicClientBuilder;
use graphql_ws_client::Client;

let mut request = "ws://localhost:8000".into_client_request().unwrap();
request.headers_mut().insert(
Expand All @@ -54,12 +54,8 @@ async fn main() {

println!("Connected");

let (sink, stream) = connection.split();

let mut client = CynicClientBuilder::new()
.build(stream, sink, TokioSpawner::current())
.await
.unwrap();
let (mut client, actor) = Client::build(connection).await.unwrap();
tokio::spawn(actor.into_future());

let mut stream = client.streaming_operation(build_query()).await.unwrap();
println!("Running subscription apparently?");
Expand Down
25 changes: 0 additions & 25 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
#[cfg(not(target_arch = "wasm32"))]
mod tokio_spawner {
pub struct TokioSpawner(tokio::runtime::Handle);

impl TokioSpawner {
pub fn new(handle: tokio::runtime::Handle) -> Self {
TokioSpawner(handle)
}

pub fn current() -> Self {
TokioSpawner::new(tokio::runtime::Handle::current())
}
}

impl futures::task::Spawn for TokioSpawner {
fn spawn_obj(
&self,
obj: futures::task::FutureObj<'static, ()>,
) -> Result<(), futures::task::SpawnError> {
self.0.spawn(obj);
Ok(())
}
}
}
#[cfg(not(target_arch = "wasm32"))]
pub use tokio_spawner::TokioSpawner;

0 comments on commit 827bec6

Please sign in to comment.