Skip to content

Commit

Permalink
chore: restructure workspace (#1887)
Browse files Browse the repository at this point in the history
Co-authored-by: Tushar Mathur <[email protected]>
  • Loading branch information
laststylebender14 and tusharmath authored May 9, 2024
1 parent 940513f commit b74f247
Show file tree
Hide file tree
Showing 204 changed files with 1,073 additions and 975 deletions.
7 changes: 3 additions & 4 deletions benches/data_loader_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ use async_trait::async_trait;
use criterion::Criterion;
use hyper::body::Bytes;
use reqwest::Request;
use tailcall::config::Batch;
use tailcall::http::{DataLoaderRequest, HttpDataLoader, Response};
use tailcall::runtime::TargetRuntime;
use tailcall::{EnvIO, FileIO, HttpIO};
use tailcall::{
Batch, DataLoaderRequest, EnvIO, FileIO, HttpDataLoader, HttpIO, Response, TargetRuntime,
};

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

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

fn request_context() -> RequestContext {
let config_module = tailcall::config::ConfigModule::default();
let config_module = tailcall::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::json::JsonLike;
use tailcall::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::json::gather_path_matches(
serde_json::to_value(tailcall::gather_path_matches(
&input,
&["data".into(), "user".into(), "id".into()],
vec![],
Expand Down
3 changes: 1 addition & 2 deletions benches/protobuf_convert_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use anyhow::Result;
use criterion::{black_box, Criterion};
use rand::{thread_rng, Fill};
use serde_json::{json, Value};
use tailcall::blueprint::GrpcMethod;
use tailcall::grpc::protobuf::ProtobufSet;
use tailcall::{GrpcMethod, ProtobufSet};

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

#[derive(Setters)]
struct Context {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use strum_macros::Display;

use crate::{config, generator};
use crate::core::{config, generator};

pub const VERSION: &str = match option_env!("APP_VERSION") {
Some(version) => version,
Expand Down
4 changes: 2 additions & 2 deletions src/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use colored::Colorize;
use derive_setters::Setters;
use thiserror::Error;

use crate::valid::ValidationError;
use crate::core::valid::ValidationError;

#[derive(Debug, Error, Setters, PartialEq, Clone)]
pub struct CLIError {
Expand Down Expand Up @@ -236,7 +236,7 @@ mod tests {
use stripmargin::StripMargin;

use super::*;
use crate::valid::Cause;
use crate::core::valid::Cause;

#[test]
fn test_no_newline() {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use colored::*;

use crate::config::Config;
use crate::core::config::Config;

pub struct Fmt {}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/javascript/js_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reqwest::Request;
use rquickjs::{FromJs, IntoJs};
use serde::{Deserialize, Serialize};

use crate::is_default;
use crate::core::is_default;

#[derive(Debug)]
pub struct JsRequest(reqwest::Request);
Expand Down
15 changes: 9 additions & 6 deletions src/cli/javascript/js_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use hyper::body::Bytes;
use rquickjs::{FromJs, IntoJs};

use super::create_header_map;
use crate::http::Response;
use crate::core::http::Response;

#[derive(Debug)]
pub struct JsResponse(Response<String>);
Expand Down Expand Up @@ -107,7 +107,7 @@ mod test {
fn create_test_response() -> Result<JsResponse> {
let mut headers = HeaderMap::new();
headers.insert("content-type", "application/json".parse().unwrap());
let response = crate::http::Response {
let response = crate::core::http::Response {
status: reqwest::StatusCode::OK,
headers,
body: Bytes::from("Hello, World!"),
Expand All @@ -132,7 +132,7 @@ mod test {
#[test]
fn test_from_js_response() {
let js_response = create_test_response().unwrap();
let response: Result<crate::http::Response<Bytes>> = js_response.try_into();
let response: Result<crate::core::http::Response<Bytes>> = js_response.try_into();
assert!(response.is_ok());
let response = response.unwrap();
assert_eq!(response.status, reqwest::StatusCode::OK);
Expand All @@ -151,11 +151,14 @@ mod test {
HeaderName::from_static("x-unusual-header"),
HeaderValue::from_str("🚀").unwrap(),
);
let response =
crate::http::Response { status: reqwest::StatusCode::OK, headers, body: body.into() };
let response = crate::core::http::Response {
status: reqwest::StatusCode::OK,
headers,
body: body.into(),
};
let js_response = JsResponse(response);

let response: Result<crate::http::Response<Bytes>, _> = js_response.try_into();
let response: Result<crate::core::http::Response<Bytes>, _> = js_response.try_into();
assert!(response.is_ok());
let response = response.unwrap();
assert_eq!(response.headers.get("x-unusual-header").unwrap(), "🚀");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/javascript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use js_response::JsResponse;
pub use request_filter::RequestFilter;
pub use runtime::Runtime;

use crate::{blueprint, HttpIO};
use crate::core::{blueprint, HttpIO};

pub fn init_http(
http: Arc<impl HttpIO>,
Expand Down
6 changes: 3 additions & 3 deletions src/cli/javascript/request_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use hyper::body::Bytes;
use rquickjs::FromJs;

use super::{JsRequest, JsResponse};
use crate::http::Response;
use crate::{HttpIO, WorkerIO};
use crate::core::http::Response;
use crate::core::{HttpIO, WorkerIO};

#[derive(Debug)]
pub enum Event {
Expand Down Expand Up @@ -106,7 +106,7 @@ mod tests {

use crate::cli::javascript::request_filter::Command;
use crate::cli::javascript::{JsRequest, JsResponse};
use crate::http::Response;
use crate::core::http::Response;

#[test]
fn test_command_from_invalid_object() {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/javascript/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rquickjs::{Context, Ctx, FromJs, Function, IntoJs, Value};

use super::request_filter::{Command, Event};
use super::JsRequest;
use crate::{blueprint, WorkerIO};
use crate::core::{blueprint, WorkerIO};

struct LocalRuntime(Context);

Expand Down
2 changes: 1 addition & 1 deletion src/cli/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};

use crate::runtime::TargetRuntime;
use crate::core::runtime::TargetRuntime;

fn cache_metrics(runtime: &TargetRuntime) -> Result<()> {
let meter = opentelemetry::global::meter("cache");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/runtime/env.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::Cow;
use std::collections::HashMap;

use crate::EnvIO;
use crate::core::EnvIO;

#[derive(Clone)]
pub struct EnvNative {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/runtime/file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use tokio::io::{AsyncReadExt, AsyncWriteExt};

use crate::cli::CLIError;
use crate::FileIO;
use crate::core::FileIO;

#[derive(Clone)]
pub struct NativeFileIO {}
Expand Down
6 changes: 3 additions & 3 deletions src/cli/runtime/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use tracing_opentelemetry::OpenTelemetrySpanExt;

use super::HttpIO;
use crate::blueprint::telemetry::Telemetry;
use crate::blueprint::Upstream;
use crate::http::Response;
use crate::core::blueprint::telemetry::Telemetry;
use crate::core::blueprint::Upstream;
use crate::core::http::Response;

static HTTP_CLIENT_REQUEST_COUNT: Lazy<Counter<u64>> = Lazy::new(|| {
let meter = opentelemetry::global::meter("http_request");
Expand Down
8 changes: 4 additions & 4 deletions src/cli/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ mod http;
use std::hash::Hash;
use std::sync::Arc;

use crate::blueprint::Blueprint;
use crate::cache::InMemoryCache;
use crate::runtime::TargetRuntime;
use crate::{blueprint, EnvIO, FileIO, HttpIO};
use crate::core::blueprint::Blueprint;
use crate::core::cache::InMemoryCache;
use crate::core::runtime::TargetRuntime;
use crate::core::{blueprint, EnvIO, FileIO, HttpIO};

// Provides access to env in native rust environment
fn init_env() -> Arc<dyn EnvIO> {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/server/http_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use hyper::service::{make_service_fn, service_fn};
use tokio::sync::oneshot;

use super::server_config::ServerConfig;
use crate::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest};
use crate::cli::CLIError;
use crate::http::handle_request;
use crate::core::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest};
use crate::core::http::handle_request;

pub async fn start_http_1(
sc: Arc<ServerConfig>,
Expand Down
4 changes: 2 additions & 2 deletions src/cli/server/http_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use rustls_pki_types::{CertificateDer, PrivateKeyDer};
use tokio::sync::oneshot;

use super::server_config::ServerConfig;
use crate::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest};
use crate::cli::CLIError;
use crate::http::handle_request;
use crate::core::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest};
use crate::core::http::handle_request;

pub async fn start_http_2(
sc: Arc<ServerConfig>,
Expand Down
4 changes: 2 additions & 2 deletions src/cli/server/server.rs → src/cli/server/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use tokio::sync::oneshot::{self};
use super::http_1::start_http_1;
use super::http_2::start_http_2;
use super::server_config::ServerConfig;
use crate::blueprint::{Blueprint, Http};
use crate::cli::telemetry::init_opentelemetry;
use crate::cli::CLIError;
use crate::config::ConfigModule;
use crate::core::blueprint::{Blueprint, Http};
use crate::core::config::ConfigModule;

pub struct Server {
config_module: ConfigModule,
Expand Down
4 changes: 2 additions & 2 deletions src/cli/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod http_1;
pub mod http_2;
pub mod server;
pub mod http_server;
pub mod server_config;

pub use server::Server;
pub use http_server::Server;

use self::server_config::ServerConfig;

Expand Down
10 changes: 5 additions & 5 deletions src/cli/server/server_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::sync::Arc;

use async_graphql_extension_apollo_tracing::ApolloTracing;

use crate::blueprint::telemetry::TelemetryExporter;
use crate::blueprint::{Blueprint, Http};
use crate::cli::runtime::init;
use crate::http::AppContext;
use crate::rest::{EndpointSet, Unchecked};
use crate::schema_extension::SchemaExtension;
use crate::core::blueprint::telemetry::TelemetryExporter;
use crate::core::blueprint::{Blueprint, Http};
use crate::core::http::AppContext;
use crate::core::rest::{EndpointSet, Unchecked};
use crate::core::schema_extension::SchemaExtension;

pub struct ServerConfig {
pub blueprint: Blueprint,
Expand Down
12 changes: 6 additions & 6 deletions src/cli/tc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use stripmargin::StripMargin;

use super::command::{Cli, Command};
use super::update_checker;
use crate::blueprint::Blueprint;
use crate::cli::fmt::Fmt;
use crate::cli::server::Server;
use crate::cli::{self, CLIError};
use crate::config::reader::ConfigReader;
use crate::generator::Generator;
use crate::http::API_URL_PREFIX;
use crate::print_schema;
use crate::rest::{EndpointSet, Unchecked};
use crate::core::blueprint::Blueprint;
use crate::core::config::reader::ConfigReader;
use crate::core::generator::Generator;
use crate::core::http::API_URL_PREFIX;
use crate::core::print_schema;
use crate::core::rest::{EndpointSet, Unchecked};

const FILE_NAME: &str = ".tailcallrc.graphql";
const YML_FILE_NAME: &str = ".graphqlrc.yml";
Expand Down
6 changes: 3 additions & 3 deletions src/cli/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::{Layer, Registry};

use super::metrics::init_metrics;
use crate::blueprint::telemetry::{OtlpExporter, Telemetry, TelemetryExporter};
use crate::cli::CLIError;
use crate::runtime::TargetRuntime;
use crate::tracing::{default_tracing_tailcall, get_log_level, tailcall_filter_target};
use crate::core::blueprint::telemetry::{OtlpExporter, Telemetry, TelemetryExporter};
use crate::core::runtime::TargetRuntime;
use crate::core::tracing::{default_tracing_tailcall, get_log_level, tailcall_filter_target};

static RESOURCE: Lazy<Resource> = Lazy::new(|| {
Resource::default().merge(&Resource::new(vec![
Expand Down
Loading

1 comment on commit b74f247

@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 7.13ms 3.34ms 179.49ms 73.10%
Req/Sec 3.55k 191.79 3.85k 91.00%

424226 requests in 30.01s, 2.13GB read

Requests/sec: 14134.97

Transfer/sec: 72.55MB

Please sign in to comment.