nakago_async_graphql/test/
utils.rs1use std::ops::Deref;
2
3use axum::Router;
4use nakago::Tag;
5use nakago_axum;
6use nakago_figment::{Config, FromRef};
7
8use super::http::GraphQL;
9
10pub struct Utils<C: Config> {
12 utils: nakago_axum::test::Utils<C>,
13
14 pub graphql: GraphQL,
16}
17
18impl<C: Config> Deref for Utils<C> {
19 type Target = nakago_axum::test::Utils<C>;
20
21 fn deref(&self) -> &Self::Target {
22 &self.utils
23 }
24}
25
26impl<C: Config> Utils<C> {
27 pub async fn init(
29 i: nakago::Inject,
30 base_url: &str,
31 graphql_url: &str,
32 router: Router,
33 ) -> nakago::Result<Self>
34 where
35 C: Config,
36 nakago_axum::Config: FromRef<C>,
37 {
38 let utils = nakago_axum::test::Utils::init(i.clone(), base_url, router).await?;
39
40 let graphql = GraphQL::new(utils.http.clone(), graphql_url.to_string());
41
42 Ok(Self { utils, graphql })
43 }
44
45 pub async fn new(
47 i: nakago::Inject,
48 base_url: &str,
49 graphql_url: &str,
50 router: Router,
51 config_tag: Option<&'static Tag<C>>,
52 ) -> nakago::Result<Self>
53 where
54 C: Config,
55 nakago_axum::Config: FromRef<C>,
56 {
57 let utils = nakago_axum::test::Utils::new(i.clone(), base_url, router, config_tag).await?;
58
59 let graphql = GraphQL::new(utils.http.clone(), graphql_url.to_string());
60
61 Ok(Self { utils, graphql })
62 }
63}