Repository: graphql-rust/juniper (language: rust)

Issue:
Why doesn't juniper_warp::make_graphql_filter take schema: Arc<RootNode<...>>?
I notice that `juniper_hyper::graphql` takes the schema/rootnode argument as type `Arc<RootNode<...>>` but `juniper_warp::make_graphql_filter` only takes the schema as `RootNode<...>`.

This seems to make `juniper_warp` difficult to use in practice in the scenario of library integrations (e.g., a juniper-based GraphQL plugin for tauri).

In the example [here](https://github.com/graphql-rust/juniper/blob/6aa63854372bf50d7134491495568593e968c7c6/juniper_warp/examples/warp_server.rs#L13) this issue is side-stepped completely by creating a function `schema()` which returns a fresh `RootNode` instance.

In a library integration, however, you do not have access to the components necessary to construct a new `RootNode`.

It seems that `juniper_warp` should take the argument as an `Arc<RootNode<...>>` like `juniper_hyper` in order to avoid this problem.

Is there a reason why it is not defined this way?
Why doesn't juniper_warp::make_graphql_filter take schema: Arc<RootNode<...>>?
I notice that `juniper_hyper::graphql` takes the schema/rootnode argument as type `Arc<RootNode<...>>` but `juniper_warp::make_graphql_filter` only takes the schema as `RootNode<...>`.

This seems to make `juniper_warp` difficult to use in practice in the scenario of library integrations (e.g., a juniper-based GraphQL plugin for tauri).

In the example [here](https://github.com/graphql-rust/juniper/blob/6aa63854372bf50d7134491495568593e968c7c6/juniper_warp/examples/warp_server.rs#L13) this issue is side-stepped completely by creating a function `schema()` which returns a fresh `RootNode` instance.

In a library integration, however, you do not have access to the components necessary to construct a new `RootNode`.

It seems that `juniper_warp` should take the argument as an `Arc<RootNode<...>>` like `juniper_hyper` in order to avoid this problem.

Is there a reason why it is not defined this way?


Discussion / hints:
@silvanshade I don't see any. It seems that authors of the code just didn't consider this use case. A PR would be appreciated.
@silvanshade I don't see any. It seems that authors of the code just didn't consider this use case. A PR would be appreciated.

Fix patch:
diff --git a/juniper_warp/CHANGELOG.md b/juniper_warp/CHANGELOG.md
index b33dfea77..8ee5d26db 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 b30b007b1..7b524d2ab 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<Query, Mutation, Subscription, CtxT, S>(
-    schema: juniper::RootNode<'static, Query, Mutation, Subscription, S>,
+    schema: impl Into<Arc<juniper::RootNode<'static, Query, Mutation, Subscription, S>>>,
     context_extractor: BoxedFilter<(CtxT,)>,
 ) -> BoxedFilter<(http::Response<Vec<u8>>,)>
 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<Query, Mutation, Subscription, CtxT, S>(
-    schema: juniper::RootNode<'static, Query, Mutation, Subscription, S>,
+    schema: impl Into<Arc<juniper::RootNode<'static, Query, Mutation, Subscription, S>>>,
     context_extractor: BoxedFilter<(CtxT,)>,
 ) -> BoxedFilter<(http::Response<Vec<u8>>,)>
 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();
 


Test patch: