1mod container;
2mod context;
3mod custom_directive;
4mod error;
5mod executor;
6mod input;
7mod operation;
8mod playground_html;
9mod query_root;
10mod request;
11mod resolver;
12mod response;
13mod test_utils;
14mod types;
15mod validation;
16mod variables;
17
18use std::path::Path;
19
20#[doc(hidden)]
21pub use async_trait;
22
23pub use container::Container;
24pub use context::{Context, ExecutionContext, SelectionSetContext};
25pub use custom_directive::CustomDirective;
26pub use error::{Error, GqlError, GqlErrorType, GqlTypedError};
27pub use executor::execute;
28use futures_util::Future;
29pub use input::GqlInputType;
30pub use operation::OperationType;
31pub use playground_html::playground_html;
32pub use query_root::QueryRoot;
33pub use request::{receive_http_request, HttpRequestError, Request};
34pub use resolver::{
35 resolve_selection_parallelly, resolve_selection_serially, CollectFields, FieldResolver, Fields,
36 SelectionSetResolver,
37};
38pub use response::Response;
39pub use test_utils::{build_test_request, check_gql_response, schema_content};
40pub use types::schema::build_schema;
41pub use types::{
42 DirectiveDefinition, EnumType, FieldType, GqlConstValue as Value, GqlDirective, GqlValue,
43 GqlValueType, InputObjectType, InputValueType, InterfaceType, ObjectType, ScalarType, Schema,
44 TypeDefinition, UnionType, ID,
45};
46pub use variables::Variables;
47
48pub type ResolverResult<T> = ::std::result::Result<T, GqlError>;
49
50pub use rusty_gql_macro::{GqlEnum, GqlInputObject, GqlInterface, GqlScalar, GqlType, GqlUnion};
51
52#[derive(Clone)]
53pub struct EmptyMutation;
54
55#[async_trait::async_trait]
56impl FieldResolver for EmptyMutation {
57 async fn resolve_field(&self, _ctx: &Context<'_>) -> ResolverResult<Option<GqlValue>> {
58 Ok(None)
59 }
60 fn type_name() -> String {
61 "Mutation".to_string()
62 }
63}
64
65impl CollectFields for EmptyMutation {}
66
67#[async_trait::async_trait]
68impl SelectionSetResolver for EmptyMutation {
69 async fn resolve_selection_set(
70 &self,
71 _ctx: &SelectionSetContext<'_>,
72 ) -> ResolverResult<GqlValue> {
73 Ok(GqlValue::Null)
74 }
75}
76
77#[derive(Clone)]
78pub struct EmptySubscription;
79
80#[async_trait::async_trait]
81impl FieldResolver for EmptySubscription {
82 async fn resolve_field(&self, _ctx: &Context<'_>) -> ResolverResult<Option<GqlValue>> {
83 Ok(None)
84 }
85 fn type_name() -> String {
86 "Subscription".to_string()
87 }
88}
89
90impl CollectFields for EmptySubscription {}
91
92#[async_trait::async_trait]
93impl SelectionSetResolver for EmptySubscription {
94 async fn resolve_selection_set(
95 &self,
96 _ctx: &SelectionSetContext<'_>,
97 ) -> ResolverResult<GqlValue> {
98 Ok(GqlValue::Null)
99 }
100}
101
102pub type ResolveFut<'a> =
103 &'a mut (dyn Future<Output = ResolverResult<Option<GqlValue>>> + Send + Unpin);
104
105pub fn read_schemas(dir: &Path) -> std::io::Result<Vec<String>> {
106 let mut schemas = Vec::new();
107 if dir.is_dir() {
108 for entry in std::fs::read_dir(dir)? {
109 let entry = entry?;
110 let path = entry.path();
111 if path.is_dir() {
112 read_schemas(&path)?;
113 } else {
114 let content = std::fs::read_to_string(path)?;
115 schemas.push(content);
116 }
117 }
118 }
119 Ok(schemas)
120}