-
Notifications
You must be signed in to change notification settings - Fork 434
GraphQL-WS crate and Warp subscriptions update #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
31e1c45
update pre-existing juniper_warp::subscriptions
ccbrown 3dd6b6b
initial draft
ccbrown ac7ea1f
finish up, update example
ccbrown eae4300
polish + timing test
ccbrown ad9ebe4
fix pre-existing bug
ccbrown cae5a5a
rebase updates
ccbrown c2c631f
address comments
ccbrown d4e39c5
add release.toml
ccbrown 6bd4690
makefile and initial changelog
ccbrown fd6c442
add new Cargo.toml to juniper/release.toml
ccbrown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# master | ||
|
||
- Initial Release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "juniper_graphql_ws" | ||
version = "0.1.0" | ||
authors = ["Christopher Brown <[email protected]>"] | ||
license = "BSD-2-Clause" | ||
description = "Graphql-ws protocol implementation for Juniper" | ||
documentation = "https://docs.rs/juniper_graphql_ws" | ||
repository = "https://github.com/graphql-rust/juniper" | ||
keywords = ["graphql-ws", "juniper", "graphql", "apollo"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
juniper = { version = "0.14.2", path = "../juniper", default-features = false } | ||
juniper_subscriptions = { path = "../juniper_subscriptions" } | ||
serde = { version = "1.0.8", features = ["derive"] } | ||
tokio = { version = "0.2", features = ["macros", "rt-core", "time"] } | ||
|
||
[dev-dependencies] | ||
serde_json = { version = "1.0.2" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[env] | ||
CARGO_MAKE_CARGO_ALL_FEATURES = "" | ||
|
||
[tasks.build-verbose] | ||
condition = { rust_version = { min = "1.29.0" } } | ||
|
||
[tasks.build-verbose.windows] | ||
condition = { rust_version = { min = "1.29.0" }, env = { "TARGET" = "x86_64-pc-windows-msvc" } } | ||
|
||
[tasks.test-verbose] | ||
condition = { rust_version = { min = "1.29.0" } } | ||
|
||
[tasks.test-verbose.windows] | ||
condition = { rust_version = { min = "1.29.0" }, env = { "TARGET" = "x86_64-pc-windows-msvc" } } | ||
|
||
[tasks.ci-coverage-flow] | ||
condition = { rust_version = { min = "1.29.0" } } | ||
|
||
[tasks.ci-coverage-flow.windows] | ||
disabled = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
no-dev-version = true | ||
pre-release-commit-message = "Release {{crate_name}} {{version}}" | ||
pro-release-commit-message = "Bump {{crate_name}} version to {{next_version}}" | ||
tag-message = "Release {{crate_name}} {{version}}" | ||
upload-doc = false | ||
pre-release-replacements = [ | ||
{file="src/lib.rs", search="docs.rs/juniper_graphql_ws/[a-z0-9\\.-]+", replace="docs.rs/juniper_graphql_ws/{{version}}"}, | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
use juniper::{ScalarValue, Variables}; | ||
|
||
/// The payload for a client's "start" message. This triggers execution of a query, mutation, or | ||
/// subscription. | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
#[serde(bound(deserialize = "S: ScalarValue"))] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct StartPayload<S: ScalarValue> { | ||
/// The document body. | ||
pub query: String, | ||
|
||
/// The optional variables. | ||
#[serde(default)] | ||
pub variables: Variables<S>, | ||
|
||
/// The optional operation name (required if the document contains multiple operations). | ||
pub operation_name: Option<String>, | ||
} | ||
|
||
/// ClientMessage defines the message types that clients can send. | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
#[serde(bound(deserialize = "S: ScalarValue"))] | ||
#[serde(rename_all = "snake_case")] | ||
#[serde(tag = "type")] | ||
pub enum ClientMessage<S: ScalarValue> { | ||
/// ConnectionInit is sent by the client upon connecting. | ||
ConnectionInit { | ||
/// Optional parameters of any type sent from the client. These are often used for | ||
/// authentication. | ||
#[serde(default)] | ||
payload: Variables<S>, | ||
}, | ||
/// Start messages are used to execute a GraphQL operation. | ||
Start { | ||
/// The id of the operation. This can be anything, but must be unique. If there are other | ||
/// in-flight operations with the same id, the message will be ignored or cause an error. | ||
id: String, | ||
|
||
/// The query, variables, and operation name. | ||
payload: StartPayload<S>, | ||
}, | ||
/// Stop messages are used to unsubscribe from a subscription. | ||
Stop { | ||
/// The id of the operation to stop. | ||
id: String, | ||
}, | ||
/// ConnectionTerminate is used to terminate the connection. | ||
ConnectionTerminate, | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use juniper::{DefaultScalarValue, InputValue}; | ||
|
||
#[test] | ||
fn test_deserialization() { | ||
type ClientMessage = super::ClientMessage<DefaultScalarValue>; | ||
|
||
assert_eq!( | ||
ClientMessage::ConnectionInit { | ||
payload: [("foo".to_string(), InputValue::scalar("bar"))] | ||
.iter() | ||
.cloned() | ||
.collect(), | ||
}, | ||
serde_json::from_str(r##"{"type": "connection_init", "payload": {"foo": "bar"}}"##) | ||
.unwrap(), | ||
); | ||
|
||
assert_eq!( | ||
ClientMessage::ConnectionInit { | ||
payload: Variables::default(), | ||
}, | ||
serde_json::from_str(r##"{"type": "connection_init"}"##).unwrap(), | ||
); | ||
|
||
assert_eq!( | ||
ClientMessage::Start { | ||
id: "foo".to_string(), | ||
payload: StartPayload { | ||
query: "query MyQuery { __typename }".to_string(), | ||
variables: [("foo".to_string(), InputValue::scalar("bar"))] | ||
.iter() | ||
.cloned() | ||
.collect(), | ||
operation_name: Some("MyQuery".to_string()), | ||
}, | ||
}, | ||
serde_json::from_str( | ||
r##"{"type": "start", "id": "foo", "payload": { | ||
"query": "query MyQuery { __typename }", | ||
"variables": { | ||
"foo": "bar" | ||
}, | ||
"operationName": "MyQuery" | ||
}}"## | ||
) | ||
.unwrap(), | ||
); | ||
|
||
assert_eq!( | ||
ClientMessage::Start { | ||
id: "foo".to_string(), | ||
payload: StartPayload { | ||
query: "query MyQuery { __typename }".to_string(), | ||
variables: Variables::default(), | ||
operation_name: None, | ||
}, | ||
}, | ||
serde_json::from_str( | ||
r##"{"type": "start", "id": "foo", "payload": { | ||
"query": "query MyQuery { __typename }" | ||
}}"## | ||
) | ||
.unwrap(), | ||
); | ||
|
||
assert_eq!( | ||
ClientMessage::Stop { | ||
id: "foo".to_string() | ||
}, | ||
serde_json::from_str(r##"{"type": "stop", "id": "foo"}"##).unwrap(), | ||
); | ||
|
||
assert_eq!( | ||
ClientMessage::ConnectionTerminate, | ||
serde_json::from_str(r##"{"type": "connection_terminate"}"##).unwrap(), | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to put this on the route?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed simpler to me, but if someone with more Warp expertise tells me it would be better for whatever reason (demonstration purposes?), I'm happy to change it.