Skip to content

Commit

Permalink
Merge juniper_graphql_transport_ws and juniper_graphql_ws crates (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron authored Oct 17, 2023
1 parent f3a1a0c commit aaf28e9
Show file tree
Hide file tree
Showing 29 changed files with 1,220 additions and 1,361 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ jobs:
- { feature: time, crate: juniper }
- { feature: url, crate: juniper }
- { feature: uuid, crate: juniper }
- { feature: graphql-transport-ws, crate: juniper_graphql_ws }
- { feature: graphql-ws, crate: juniper_graphql_ws }
- { feature: <none>, crate: juniper_actix }
- { feature: subscriptions, crate: juniper_actix }
- { feature: <none>, crate: juniper_warp }
Expand Down Expand Up @@ -134,7 +136,6 @@ jobs:
- juniper_codegen
- juniper
- juniper_subscriptions
- juniper_graphql_transport_ws
- juniper_graphql_ws
#- juniper_actix
- juniper_hyper
Expand Down Expand Up @@ -189,7 +190,6 @@ jobs:
- juniper_codegen
- juniper
- juniper_subscriptions
- juniper_graphql_transport_ws
- juniper_graphql_ws
- juniper_integration_tests
- juniper_codegen_tests
Expand Down Expand Up @@ -318,7 +318,6 @@ jobs:
- juniper_codegen
- juniper
- juniper_subscriptions
- juniper_graphql_transport_ws
- juniper_graphql_ws
- juniper_actix
- juniper_hyper
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ members = [
"juniper_iron",
"juniper_rocket",
"juniper_subscriptions",
"juniper_graphql_transport_ws",
"juniper_graphql_ws",
"juniper_warp",
"juniper_actix",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ifeq ($(clean),yes)
cargo clean
endif
$(eval target := $(strip $(shell cargo -vV | sed -n 's/host: //p')))
cargo build
cargo build --all-features
mdbook test book -L target/debug/deps $(strip \
$(if $(call eq,$(findstring windows,$(target)),),,\
$(shell cargo metadata -q \
Expand Down
4 changes: 1 addition & 3 deletions juniper_actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ rustdoc-args = ["--cfg", "docsrs"]
subscriptions = [
"dep:actix",
"dep:actix-web-actors",
"dep:juniper_graphql_transport_ws",
"dep:juniper_graphql_ws",
"dep:tokio",
]
Expand All @@ -35,8 +34,7 @@ actix-web-actors = { version = "4.1", optional = true }
anyhow = "1.0.47"
futures = "0.3.22"
juniper = { version = "0.16.0-dev", path = "../juniper", default-features = false }
juniper_graphql_transport_ws = { version = "0.4.0-dev", path = "../juniper_graphql_transport_ws", optional = true }
juniper_graphql_ws = { version = "0.4.0-dev", path = "../juniper_graphql_ws", optional = true }
juniper_graphql_ws = { version = "0.4.0-dev", path = "../juniper_graphql_ws", features = ["graphql-transport-ws", "graphql-ws"], optional = true }
http = "0.2.4"
serde = { version = "1.0.122", features = ["derive"] }
serde_json = "1.0.18"
Expand Down
34 changes: 16 additions & 18 deletions juniper_actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub mod subscriptions {
SinkExt as _, Stream, StreamExt as _,
};
use juniper::{GraphQLSubscriptionType, GraphQLTypeAsync, RootNode, ScalarValue};
use juniper_graphql_transport_ws::{ArcSchema, Init};
use juniper_graphql_ws::{graphql_transport_ws, graphql_ws, ArcSchema, Init};
use tokio::sync::Mutex;

/// Serves by auto-selecting between the
Expand All @@ -194,11 +194,10 @@ pub mod subscriptions {
/// The `schema` argument is your [`juniper`] schema.
///
/// The `init` argument is used to provide the custom [`juniper::Context`] and additional
/// configuration for connections. This can be a
/// [`juniper_graphql_transport_ws::ConnectionConfig`] if the context and configuration are
/// already known, or it can be a closure that gets executed asynchronously whenever a client
/// sends the subscription initialization message. Using a closure allows to perform an
/// authentication based on the parameters provided by a client.
/// configuration for connections. This can be a [`juniper_graphql_ws::ConnectionConfig`] if the
/// context and configuration are already known, or it can be a closure that gets executed
/// asynchronously whenever a client sends the subscription initialization message. Using a
/// closure allows to perform an authentication based on the parameters provided by a client.
///
/// [new]: https://github.com/enisdenjo/graphql-ws/blob/v5.14.0/PROTOCOL.md
/// [old]: https://github.com/apollographql/subscriptions-transport-ws/blob/v0.11.0/PROTOCOL.md
Expand Down Expand Up @@ -262,8 +261,7 @@ pub mod subscriptions {
S: ScalarValue + Send + Sync + 'static,
I: Init<S, CtxT> + Send,
{
let (s_tx, s_rx) =
juniper_graphql_ws::Connection::new(ArcSchema(schema), init).split::<Message>();
let (s_tx, s_rx) = graphql_ws::Connection::new(ArcSchema(schema), init).split::<Message>();

let mut resp = ws::start(
Actor {
Expand All @@ -285,10 +283,10 @@ pub mod subscriptions {
/// Serves the [new `graphql-transport-ws` GraphQL over WebSocket Protocol][new].
///
/// The `init` argument is used to provide the context and additional configuration for
/// connections. This can be a [`juniper_graphql_transport_ws::ConnectionConfig`] if the context
/// and configuration are already known, or it can be a closure that gets executed
/// asynchronously when the client sends the `ConnectionInit` message. Using a closure allows to
/// perform an authentication based on the parameters provided by a client.
/// connections. This can be a [`juniper_graphql_ws::ConnectionConfig`] if the context and
/// configuration are already known, or it can be a closure that gets executed asynchronously
/// when the client sends the `ConnectionInit` message. Using a closure allows to perform an
/// authentication based on the parameters provided by a client.
///
/// [new]: https://github.com/enisdenjo/graphql-ws/blob/v5.14.0/PROTOCOL.md
pub async fn graphql_transport_ws_handler<Query, Mutation, Subscription, CtxT, S, I>(
Expand All @@ -308,8 +306,8 @@ pub mod subscriptions {
S: ScalarValue + Send + Sync + 'static,
I: Init<S, CtxT> + Send,
{
let (s_tx, s_rx) = juniper_graphql_transport_ws::Connection::new(ArcSchema(schema), init)
.split::<Message>();
let (s_tx, s_rx) =
graphql_transport_ws::Connection::new(ArcSchema(schema), init).split::<Message>();

let mut resp = ws::start(
Actor {
Expand Down Expand Up @@ -429,7 +427,7 @@ pub mod subscriptions {
fn into_ws_response(self) -> Result<String, ws::CloseReason>;
}

impl<S: ScalarValue> IntoWsResponse for juniper_graphql_transport_ws::Output<S> {
impl<S: ScalarValue> IntoWsResponse for graphql_transport_ws::Output<S> {
fn into_ws_response(self) -> Result<String, ws::CloseReason> {
match self {
Self::Message(msg) => serde_json::to_string(&msg).map_err(|e| ws::CloseReason {
Expand All @@ -444,7 +442,7 @@ pub mod subscriptions {
}
}

impl<S: ScalarValue> IntoWsResponse for juniper_graphql_ws::ServerMessage<S> {
impl<S: ScalarValue> IntoWsResponse for graphql_ws::ServerMessage<S> {
fn into_ws_response(self) -> Result<String, ws::CloseReason> {
serde_json::to_string(&self).map_err(|e| ws::CloseReason {
code: ws::CloseCode::Error,
Expand All @@ -456,7 +454,7 @@ pub mod subscriptions {
#[derive(Debug)]
struct Message(ws::Message);

impl<S: ScalarValue> TryFrom<Message> for juniper_graphql_transport_ws::Input<S> {
impl<S: ScalarValue> TryFrom<Message> for graphql_transport_ws::Input<S> {
type Error = Error;

fn try_from(msg: Message) -> Result<Self, Self::Error> {
Expand All @@ -470,7 +468,7 @@ pub mod subscriptions {
}
}

impl<S: ScalarValue> TryFrom<Message> for juniper_graphql_ws::ClientMessage<S> {
impl<S: ScalarValue> TryFrom<Message> for graphql_ws::ClientMessage<S> {
type Error = Error;

fn try_from(msg: Message) -> Result<Self, Self::Error> {
Expand Down
27 changes: 0 additions & 27 deletions juniper_graphql_transport_ws/CHANGELOG.md

This file was deleted.

25 changes: 0 additions & 25 deletions juniper_graphql_transport_ws/Cargo.toml

This file was deleted.

25 changes: 0 additions & 25 deletions juniper_graphql_transport_ws/LICENSE

This file was deleted.

29 changes: 0 additions & 29 deletions juniper_graphql_transport_ws/README.md

This file was deleted.

24 changes: 0 additions & 24 deletions juniper_graphql_transport_ws/release.toml

This file was deleted.

2 changes: 0 additions & 2 deletions juniper_graphql_transport_ws/src/schema.rs

This file was deleted.

14 changes: 12 additions & 2 deletions juniper_graphql_ws/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ All user visible changes to `juniper_graphql_ws` crate will be documented in thi

### BC Breaks

- Moved existing implementation to `graphql_ws` module implementing [legacy `graphql-ws` GraphQL over WebSocket Protocol][proto-legacy] behind `graphql-ws` Cargo feature. ([#1196])
- Switched to 0.16 version of [`juniper` crate].
- Switched to 0.17 version of [`juniper_subscriptions` crate].

### Added

- `graphql_transport_ws` module implementing [`graphql-transport-ws` GraphQL over WebSocket Protocol][proto-5.14.0] as of 5.14.0 version of [`graphql-ws` npm package] behind `graphql-transport-ws` Cargo feature. ([#1158], [#1191], [#1196], [#1022])

### Changed

- Made fields of `ConnectionConfig` public to reuse in [`juniper_graphql_transport_ws` crate]. ([#1191])
- Made fields of `ConnectionConfig` public. ([#1191])

[#1022]: /../../issues/1022
[#1158]: /../../pull/1158
[#1191]: /../../pull/1191
[#1196]: /../../pull/1196
[proto-5.14.0]: https://github.com/enisdenjo/graphql-ws/blob/v5.14.0/PROTOCOL.md
[proto-legacy]: https://github.com/apollographql/subscriptions-transport-ws/blob/v0.11.0/PROTOCOL.md



Expand All @@ -29,7 +39,7 @@ See [old CHANGELOG](/../../blob/juniper_graphql_ws-v0.3.0/juniper_graphql_ws/CHA



[`graphql-ws` npm package]: https://npmjs.com/package/graphql-ws
[`juniper` crate]: https://docs.rs/juniper
[`juniper_graphql_transport_ws` crate]: https://docs.rs/juniper_graphql_transport_ws
[`juniper_subscriptions` crate]: https://docs.rs/juniper_subscriptions
[Semantic Versioning 2.0.0]: https://semver.org
17 changes: 14 additions & 3 deletions juniper_graphql_ws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@ name = "juniper_graphql_ws"
version = "0.4.0-dev"
edition = "2021"
rust-version = "1.65"
description = "Legacy `graphql-ws` GraphQL over WebSocket Protocol implementation for `juniper` crate."
description = "GraphQL over WebSocket Protocol implementations for `juniper` crate."
license = "BSD-2-Clause"
authors = ["Christopher Brown <ccbrown112@gmail.com>"]
authors = [
"Christopher Brown <ccbrown112@gmail.com>",
"Kai Ren <tyranron@gmail.com>",
]
documentation = "https://docs.rs/juniper_graphql_ws"
homepage = "https://github.com/graphql-rust/juniper/tree/master/juniper_graphql_ws"
repository = "https://github.com/graphql-rust/juniper"
readme = "README.md"
categories = ["asynchronous", "web-programming", "web-programming::http-server"]
keywords = ["apollo", "graphql", "graphql-ws", "subscription", "websocket"]
keywords = ["apollo", "graphql-transport-ws", "graphql-ws", "subscription", "websocket"]
exclude = ["/release.toml"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
graphql-transport-ws = []
graphql-ws = []

[dependencies]
juniper = { version = "0.16.0-dev", path = "../juniper", default-features = false }
juniper_subscriptions = { version = "0.17.0-dev", path = "../juniper_subscriptions" }
Expand Down
7 changes: 5 additions & 2 deletions juniper_graphql_ws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

- [Changelog](https://github.com/graphql-rust/juniper/blob/master/juniper_graphql_ws/CHANGELOG.md)

This crate contains an implementation of the [legacy `graphql-ws` GraphQL over WebSocket Protocol][old], as formerly used by [Apollo] and [`subscriptions-transport-ws` npm package]. It has now been deprecated in favor of the [new `graphql-transport-ws` GraphQL over WebSocket Protocol][new], implemented by the new [`juniper_graphql_transport_ws` crate] and new [`graphql-ws` npm package].
This crate contains implementations of 2 protocols:

1. (`graphql-transport-ws` feature) The [new `graphql-transport-ws` GraphQL over WebSocket Protocol][new], as now used by [Apollo] and [`graphql-ws` npm package].

2. (`graphql-ws` feature) The [legacy `graphql-ws` GraphQL over WebSocket Protocol][old], as formerly used by [Apollo] and [`subscriptions-transport-ws` npm package] (deprecated in favor of the [new `graphql-transport-ws` GraphQL over WebSocket Protocol][new] mentioned above).



Expand All @@ -21,7 +25,6 @@ This project is licensed under [BSD 2-Clause License](https://github.com/graphql


[`graphql-ws` npm package]: https://npmjs.com/package/graphql-ws
[`juniper_graphql_transport_ws` crate]: https://docs.rs/juniper_graphql_transport_ws
[`subscriptions-transport-ws` npm package]: https://npmjs.com/package/subscriptions-transport-ws
[Apollo]: https://www.apollographql.com
[new]: https://github.com/enisdenjo/graphql-ws/blob/v5.14.0/PROTOCOL.md
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use juniper::Variables;
use serde::Deserialize;

use crate::utils::default_for_null;
use crate::util::default_for_null;

/// The payload for a client's "start" message. This triggers execution of a query, mutation, or
/// subscription.
Expand Down
Loading

0 comments on commit aaf28e9

Please sign in to comment.