From 9e0b9692a9a7ec4d521e46e1bd460cfcfb3eb1af Mon Sep 17 00:00:00 2001 From: Darin Morrison Date: Fri, 20 Jan 2023 12:15:35 -0700 Subject: [PATCH] Allow to specify already `Arc`ed schema in `juniper_warp` (#1136, #1135) Co-authored-by: Kai Ren --- juniper_warp/CHANGELOG.md | 7 +++++++ juniper_warp/src/lib.rs | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/juniper_warp/CHANGELOG.md b/juniper_warp/CHANGELOG.md index b33dfea7..8ee5d26d 100644 --- a/juniper_warp/CHANGELOG.md +++ b/juniper_warp/CHANGELOG.md @@ -12,6 +12,13 @@ All user visible changes to `juniper_warp` crate will be documented in this file - Switched to 0.16 version of [`juniper` crate]. +### Changed + +- Made `schema` argument of `make_graphql_filter()` and `make_graphql_filter_sync()` polymorphic, allowing to specify external `Arc`ed `schema`. ([#1136], [#1135]) + +[#1135]: /../../issues/1136 +[#1136]: /../../pull/1136 + diff --git a/juniper_warp/src/lib.rs b/juniper_warp/src/lib.rs index b30b007b..7b524d2a 100644 --- a/juniper_warp/src/lib.rs +++ b/juniper_warp/src/lib.rs @@ -70,7 +70,7 @@ use warp::{body, filters::BoxedFilter, http, hyper::body::Bytes, query, Filter}; /// .and(graphql_filter); /// ``` pub fn make_graphql_filter( - schema: juniper::RootNode<'static, Query, Mutation, Subscription, S>, + schema: impl Into>>, context_extractor: BoxedFilter<(CtxT,)>, ) -> BoxedFilter<(http::Response>,)> where @@ -83,7 +83,7 @@ where CtxT: Send + Sync + 'static, S: ScalarValue + Send + Sync + 'static, { - let schema = Arc::new(schema); + let schema = schema.into(); let post_json_schema = schema.clone(); let post_graphql_schema = schema.clone(); @@ -155,7 +155,7 @@ where /// Make a synchronous filter for graphql endpoint. pub fn make_graphql_filter_sync( - schema: juniper::RootNode<'static, Query, Mutation, Subscription, S>, + schema: impl Into>>, context_extractor: BoxedFilter<(CtxT,)>, ) -> BoxedFilter<(http::Response>,)> where @@ -165,7 +165,7 @@ where CtxT: Send + Sync + 'static, S: ScalarValue + Send + Sync + 'static, { - let schema = Arc::new(schema); + let schema = schema.into(); let post_json_schema = schema.clone(); let post_graphql_schema = schema.clone();