Skip to content

Commit

Permalink
refactor: drop the root level types (#1969)
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath authored May 15, 2024
1 parent 742c376 commit 869c960
Show file tree
Hide file tree
Showing 32 changed files with 99 additions and 86 deletions.
9 changes: 5 additions & 4 deletions benches/data_loader_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use async_trait::async_trait;
use criterion::Criterion;
use hyper::body::Bytes;
use reqwest::Request;
use tailcall::{
Batch, DataLoaderRequest, EnvIO, FileIO, HttpDataLoader, HttpIO, Response, TargetRuntime,
};
use tailcall::core::config::Batch;
use tailcall::core::http::{DataLoaderRequest, HttpDataLoader, Response};
use tailcall::core::runtime::TargetRuntime;
use tailcall::core::{EnvIO, FileIO, HttpIO};

#[derive(Clone)]
struct MockHttpClient {
Expand Down Expand Up @@ -50,7 +51,7 @@ impl FileIO for File {

struct Cache;
#[async_trait]
impl tailcall::Cache for Cache {
impl tailcall::core::Cache for Cache {
type Key = u64;
type Value = ConstValue;

Expand Down
6 changes: 5 additions & 1 deletion benches/handle_request_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use std::sync::Arc;
use criterion::Criterion;
use hyper::Request;
use tailcall::cli::server::server_config::ServerConfig;
use tailcall::{handle_request, Blueprint, Config, ConfigModule, GraphQLRequest, Validator};
use tailcall::core::async_graphql_hyper::GraphQLRequest;
use tailcall::core::blueprint::Blueprint;
use tailcall::core::config::{Config, ConfigModule};
use tailcall::core::http::handle_request;
use tailcall::core::valid::Validator;

static QUERY: &str = r#"{"query":"query{posts{title}}"}"#;

Expand Down
13 changes: 8 additions & 5 deletions benches/impl_path_string_for_evaluation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ use indexmap::IndexMap;
use once_cell::sync::Lazy;
use reqwest::{Client, Request};
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use tailcall::{
EnvIO, EvaluationContext, FileIO, HttpIO, InMemoryCache, PathString, RequestContext,
ResolverContextLike, Response, Server, TargetRuntime, Upstream,
};
use tailcall::core::blueprint::{Server, Upstream};
use tailcall::core::cache::InMemoryCache;
use tailcall::core::http::{RequestContext, Response};
use tailcall::core::lambda::{EvaluationContext, ResolverContextLike};
use tailcall::core::path::PathString;
use tailcall::core::runtime::TargetRuntime;
use tailcall::core::{EnvIO, FileIO, HttpIO};

struct Http {
client: ClientWithMiddleware,
Expand Down Expand Up @@ -228,7 +231,7 @@ fn assert_test(eval_ctx: &EvaluationContext<'_, MockGraphqlContext>) {
}

fn request_context() -> RequestContext {
let config_module = tailcall::ConfigModule::default();
let config_module = tailcall::core::config::ConfigModule::default();

//TODO: default is used only in tests. Drop default and move it to test.
let upstream = Upstream::try_from(&config_module).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions benches/json_like_bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use criterion::{black_box, Criterion};
use serde_json::json;
use tailcall::JsonLike;
use tailcall::core::json::{gather_path_matches, JsonLike};

pub fn benchmark_batched_body(c: &mut Criterion) {
c.bench_function("test_batched_body", |b| {
Expand All @@ -19,7 +19,7 @@ pub fn benchmark_batched_body(c: &mut Criterion) {
});

black_box(
serde_json::to_value(tailcall::gather_path_matches(
serde_json::to_value(gather_path_matches(
&input,
&["data".into(), "user".into(), "id".into()],
vec![],
Expand Down
3 changes: 2 additions & 1 deletion benches/protobuf_convert_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use anyhow::Result;
use criterion::{black_box, Criterion};
use rand::{thread_rng, Fill};
use serde_json::{json, Value};
use tailcall::{GrpcMethod, ProtobufSet};
use tailcall::core::blueprint::GrpcMethod;
use tailcall::core::grpc::protobuf::ProtobufSet;

const PROTO_DIR: &str = "benches/grpc";
const PROTO_FILE: &str = "dummy.proto";
Expand Down
5 changes: 4 additions & 1 deletion benches/request_template_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use criterion::{black_box, Criterion};
use derive_setters::Setters;
use hyper::HeaderMap;
use serde_json::json;
use tailcall::{Endpoint, HasHeaders, PathString, RequestTemplate};
use tailcall::core::endpoint::Endpoint;
use tailcall::core::has_headers::HasHeaders;
use tailcall::core::http::RequestTemplate;
use tailcall::core::path::PathString;

#[derive(Setters)]
struct Context {
Expand Down
35 changes: 1 addition & 34 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
mod core;
pub mod core;

#[cfg(feature = "cli")]
pub mod cli;

// export only what's requried outside.
pub use core::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest};
pub use core::blueprint::{
Blueprint, Definition, DynamicValue, GrpcMethod, Script, Server, Type, Upstream,
};
pub use core::cache::InMemoryCache;
pub use core::config::reader::ConfigReader;
pub use core::config::{Batch, Config, ConfigModule, Source};
pub use core::endpoint::Endpoint;
pub use core::generator::Generator;
pub use core::grpc::protobuf::ProtobufSet;
pub use core::has_headers::HasHeaders;
pub use core::http::{
handle_request, showcase, AppContext, DataLoaderRequest, HttpDataLoader, Method,
RequestContext, RequestTemplate, Response, API_URL_PREFIX,
};
pub use core::json::{gather_path_matches, JsonLike};
pub use core::lambda::{
EmptyResolverContext, Eval, EvaluationContext, EvaluationError, Expression, ResolverContextLike,
};
pub use core::merge_right::MergeRight;
pub use core::mustache::Mustache;
pub use core::path::PathString;
pub use core::print_schema::print_schema;
pub use core::runtime::TargetRuntime;
pub use core::scalar::{is_predefined_scalar, CUSTOM_SCALARS};
pub use core::tracing::{
default_tracing, default_tracing_for_name, default_tracing_tailcall, get_log_level,
tailcall_filter_target,
};
pub use core::valid::{Cause, ValidationError, Validator};
pub use core::{Cache, EntityCache, EnvIO, FileIO, HttpIO, WorkerIO};
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::cell::Cell;

use mimalloc::MiMalloc;
use tailcall::cli::CLIError;
use tailcall::default_tracing_tailcall;
use tailcall::core::tracing::default_tracing_tailcall;
use tracing::subscriber::DefaultGuard;

#[global_allocator]
Expand Down
3 changes: 2 additions & 1 deletion tailcall-aws-lambda/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use anyhow::Result;
use hyper::body::Bytes;
use lambda_http::RequestExt;
use reqwest::Client;
use tailcall::{HttpIO, Response};
use tailcall::core::http::Response;
use tailcall::core::HttpIO;

#[derive(Clone)]
pub struct LambdaHttp {
Expand Down
8 changes: 5 additions & 3 deletions tailcall-aws-lambda/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use dotenvy::dotenv;
use http::{to_request, to_response};
use lambda_http::{run, service_fn, Body, Error, Response};
use runtime::init_runtime;
use tailcall::{
get_log_level, handle_request, AppContext, Blueprint, ConfigReader, GraphQLRequest,
};
use tailcall::core::async_graphql_hyper::GraphQLRequest;
use tailcall::core::blueprint::Blueprint;
use tailcall::core::config::reader::ConfigReader;
use tailcall::core::http::{handle_request, AppContext};
use tailcall::core::tracing::get_log_level;

mod http;
mod runtime;
Expand Down
4 changes: 3 additions & 1 deletion tailcall-aws-lambda/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::borrow::Cow;
use std::sync::Arc;

use anyhow::anyhow;
use tailcall::{EntityCache, EnvIO, FileIO, InMemoryCache, TargetRuntime};
use tailcall::core::cache::InMemoryCache;
use tailcall::core::runtime::TargetRuntime;
use tailcall::core::{EntityCache, EnvIO, FileIO};
use tokio::io::AsyncReadExt;

use crate::http::init_http;
Expand Down
2 changes: 1 addition & 1 deletion tailcall-cloudflare/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::rc::Rc;
use anyhow::Result;
use async_graphql_value::ConstValue;
use serde_json::Value;
use tailcall::Cache;
use tailcall::core::Cache;
use worker::kv::KvStore;

use crate::to_anyhow;
Expand Down
2 changes: 1 addition & 1 deletion tailcall-cloudflare/src/env.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::Cow;
use std::rc::Rc;

use tailcall::EnvIO;
use tailcall::core::EnvIO;
use worker::Env;

pub struct CloudflareEnv {
Expand Down
2 changes: 1 addition & 1 deletion tailcall-cloudflare/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::rc::Rc;

use anyhow::anyhow;
use async_std::task::spawn_local;
use tailcall::FileIO;
use tailcall::core::FileIO;
use worker::Env;

use crate::to_anyhow;
Expand Down
3 changes: 2 additions & 1 deletion tailcall-cloudflare/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use std::sync::{Arc, RwLock};

use hyper::{Body, Request, Response};
use lazy_static::lazy_static;
use tailcall::{handle_request, showcase, AppContext, GraphQLRequest};
use tailcall::core::async_graphql_hyper::GraphQLRequest;
use tailcall::core::http::{handle_request, showcase, AppContext};

use crate::http::{to_request, to_response};
use crate::runtime;
Expand Down
3 changes: 2 additions & 1 deletion tailcall-cloudflare/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use anyhow::{anyhow, Result};
use async_std::task::spawn_local;
use hyper::body::Bytes;
use reqwest::Client;
use tailcall::{HttpIO, Response};
use tailcall::core::http::Response;
use tailcall::core::HttpIO;

use crate::to_anyhow;

Expand Down
7 changes: 5 additions & 2 deletions tailcall-cloudflare/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::sync::Arc;

use anyhow::anyhow;
use async_graphql_value::ConstValue;
use tailcall::{EnvIO, FileIO, HttpIO, TargetRuntime};
use tailcall::core::runtime::TargetRuntime;
use tailcall::core::{EnvIO, FileIO, HttpIO};

use crate::{cache, env, file, http};

Expand All @@ -19,7 +20,9 @@ fn init_http() -> Arc<dyn HttpIO> {
Arc::new(http::CloudflareHttp::init())
}

fn init_cache(env: Rc<worker::Env>) -> Arc<dyn tailcall::Cache<Key = u64, Value = ConstValue>> {
fn init_cache(
env: Rc<worker::Env>,
) -> Arc<dyn tailcall::core::Cache<Key = u64, Value = ConstValue>> {
Arc::new(cache::CloudflareChronoCache::init(env))
}

Expand Down
3 changes: 2 additions & 1 deletion tailcall-query-plan/src/execution/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use async_graphql::{Name, Value};
use dashmap::DashMap;
use futures_util::future::{join_all, try_join_all};
use indexmap::IndexMap;
use tailcall::{EvaluationContext, RequestContext, ResolverContextLike};
use tailcall::core::http::RequestContext;
use tailcall::core::lambda::{EvaluationContext, ResolverContextLike};

use super::step::ExecutionStep;
use crate::plan::{GeneralPlan, OperationPlan};
Expand Down
3 changes: 2 additions & 1 deletion tailcall-query-plan/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use async_graphql::parser::types::{Selection, SelectionSet};
use async_graphql::{Name, Value};
use indenter::indented;
use indexmap::IndexMap;
use tailcall::{is_predefined_scalar, Definition, Type};
use tailcall::core::blueprint::{Definition, Type};
use tailcall::core::scalar::is_predefined_scalar;

use super::execution::executor::{ExecutionResult, ResolvedEntry};
use super::resolver::{FieldPlan, FieldPlanSelection, Id};
Expand Down
2 changes: 1 addition & 1 deletion tailcall-query-plan/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Result;
use async_graphql::parser::types::{Field, Selection, SelectionSet};
use async_graphql::{Positioned, Value};
use indenter::indented;
use tailcall::{Eval, EvaluationContext, Expression, ResolverContextLike};
use tailcall::core::lambda::{Eval, EvaluationContext, Expression, ResolverContextLike};

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Id(pub usize);
Expand Down
5 changes: 4 additions & 1 deletion tailcall-query-plan/tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::fs;
use std::path::Path;

use async_graphql::parser::parse_query;
use tailcall::{Blueprint, Config, ConfigModule, RequestContext, Validator};
use tailcall::core::blueprint::Blueprint;
use tailcall::core::config::{Config, ConfigModule};
use tailcall::core::http::RequestContext;
use tailcall::core::valid::Validator;
use tailcall_query_plan::execution::executor::Executor;
use tailcall_query_plan::execution::simple::SimpleExecutionBuilder;
use tailcall_query_plan::plan::{GeneralPlan, OperationPlan};
Expand Down
3 changes: 2 additions & 1 deletion tailcall-typedefs/src/gen_gql_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use schemars::schema::{
ArrayValidation, InstanceType, ObjectValidation, Schema, SchemaObject, SingleOrVec,
};
use schemars::Map;
use tailcall::{Config, CUSTOM_SCALARS};
use tailcall::core::config::Config;
use tailcall::core::scalar::CUSTOM_SCALARS;

static GRAPHQL_SCHEMA_FILE: &str = "generated/.tailcallrc.graphql";

Expand Down
5 changes: 4 additions & 1 deletion tailcall-typedefs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use gen_gql_schema::update_gql;
use schemars::schema::{RootSchema, Schema};
use schemars::Map;
use serde_json::{json, Value};
use tailcall::{cli, default_tracing_for_name, Config, CUSTOM_SCALARS};
use tailcall::cli;
use tailcall::core::config::Config;
use tailcall::core::scalar::CUSTOM_SCALARS;
use tailcall::core::tracing::default_tracing_for_name;

static JSON_SCHEMA_FILE: &str = "../generated/.tailcallrc.schema.json";

Expand Down
2 changes: 1 addition & 1 deletion tests/core/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate core;
use std::borrow::Cow;
use std::collections::HashMap;

use tailcall::EnvIO;
use tailcall::core::EnvIO;

#[derive(Clone)]
pub struct Env {
Expand Down
2 changes: 1 addition & 1 deletion tests/core/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate core;
use std::path::PathBuf;

use anyhow::{anyhow, Context};
use tailcall::FileIO;
use tailcall::core::FileIO;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

use super::runtime::ExecutionSpec;
Expand Down
3 changes: 2 additions & 1 deletion tests/core/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use std::sync::Arc;
use anyhow::anyhow;
use hyper::body::Bytes;
use reqwest::header::{HeaderName, HeaderValue};
use tailcall::{HttpIO, Response};
use tailcall::core::http::Response;
use tailcall::core::HttpIO;

use super::runtime::{ExecutionMock, ExecutionSpec};

Expand Down
2 changes: 1 addition & 1 deletion tests/core/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::Path;

use serde::{Deserialize, Serialize};
use serde_json::Value;
use tailcall::Method;
use tailcall::core::http::Method;
use url::Url;

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down
7 changes: 6 additions & 1 deletion tests/core/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ use anyhow::anyhow;
use markdown::mdast::Node;
use markdown::ParseOptions;
use tailcall::cli::javascript;
use tailcall::{AppContext, Blueprint, ConfigModule, EnvIO, InMemoryCache, Source, TargetRuntime};
use tailcall::core::blueprint::Blueprint;
use tailcall::core::cache::InMemoryCache;
use tailcall::core::config::{ConfigModule, Source};
use tailcall::core::http::AppContext;
use tailcall::core::runtime::TargetRuntime;
use tailcall::core::EnvIO;

use super::file::File;
use super::http::Http;
Expand Down
5 changes: 4 additions & 1 deletion tests/core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use std::sync::Arc;

use derive_setters::Setters;
use tailcall::cli::javascript;
use tailcall::{InMemoryCache, Script, Source, TargetRuntime};
use tailcall::core::blueprint::Script;
use tailcall::core::cache::InMemoryCache;
use tailcall::core::config::Source;
use tailcall::core::runtime::TargetRuntime;

use super::env::Env;
use super::file::TestFileIO;
Expand Down
12 changes: 8 additions & 4 deletions tests/core/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ use colored::Colorize;
use futures_util::future::join_all;
use hyper::{Body, Request};
use serde::{Deserialize, Serialize};
use tailcall::{
handle_request, print_schema, AppContext, Blueprint, Cause, Config, ConfigModule, ConfigReader,
GraphQLBatchRequest, GraphQLRequest, MergeRight, Source, ValidationError,
};
use tailcall::core::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest};
use tailcall::core::blueprint::Blueprint;
use tailcall::core::config::reader::ConfigReader;
use tailcall::core::config::{Config, ConfigModule, Source};
use tailcall::core::http::{handle_request, AppContext};
use tailcall::core::merge_right::MergeRight;
use tailcall::core::print_schema::print_schema;
use tailcall::core::valid::{Cause, ValidationError};

use super::file::File;
use super::http::Http;
Expand Down
Loading

1 comment on commit 869c960

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 6.97ms 3.27ms 101.88ms 74.54%
Req/Sec 3.64k 179.94 3.95k 91.92%

434438 requests in 30.01s, 2.18GB read

Requests/sec: 14478.36

Transfer/sec: 74.31MB

Please sign in to comment.