Skip to content

Commit

Permalink
Merge branch 'main' into fix/graphql_nested_queries
Browse files Browse the repository at this point in the history
  • Loading branch information
MedHeikelBouzayene authored Nov 5, 2024
2 parents 92a9d2c + fb0974d commit 68db95f
Show file tree
Hide file tree
Showing 129 changed files with 395 additions and 914 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
macro_benchmarks:
name: Macro Benchmarks
if: "${{ contains(github.event.pull_request.labels.*.name, 'ci: benchmark') || github.event_name == 'push' }}"
runs-on: benchmarking-runner
runs-on:
group: benchmarking-runner
permissions:
pull-requests: write
contents: write
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/benchmark_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ concurrency:
jobs:
micro_benchmarks:
name: Micro Benchmarks
runs-on: benchmarking-runner
runs-on:
group: benchmarking-runner
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/benchmark_pr_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
micro_benchmarks_pr_run:
name: Micro Benchmarks for PR
if: "${{ contains(github.event.pull_request.labels.*.name, 'ci: benchmark') }}"
runs-on: benchmarking-runner
runs-on:
group: benchmarking-runner
steps:
- uses: actions/checkout@v4
- name: Run Benchmarks
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ jobs:
with:
target: wasm32-unknown-unknown

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: "20.11.0"

- name: Install Wasm Pack
run: cargo install wasm-bindgen-cli --vers "0.2.92"

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/nginx-benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
nginx_benchmarks:
name: Nginx Benchmarks
if: "contains(github.event.pull_request.labels.*.name, 'ci: benchmark') || github.event_name == 'push'"
runs-on: benchmarking-runner
runs-on:
group: benchmarking-runner
permissions:
pull-requests: write
contents: write
Expand Down
2 changes: 1 addition & 1 deletion .nightly/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-06-01"
channel = "nightly-2024-10-20"
profile = "default"
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ derive_more = "0.99.18"
thiserror = "1.0.59"
url = { version = "2.5.0", features = ["serde"] }
convert_case = "0.6.0"
tailcall-valid = "0.1.1"

[dependencies]
# dependencies specific to CLI must have optional = true and the dep should be added to default feature.
Expand Down Expand Up @@ -169,6 +170,7 @@ num = "0.4.3"
indenter = "0.3.3"
derive_more = { workspace = true }
strum = "0.26.2"
tailcall-valid = { workspace = true }
dashmap = "6.1.0"
urlencoding = "2.1.3"

Expand Down
2 changes: 1 addition & 1 deletion benches/handle_request_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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;
use tailcall_valid::Validator;

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

Expand Down
2 changes: 1 addition & 1 deletion benches/request_template_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl PathValue for Context {
}

impl PathString for Context {
fn path_string<'a, T: AsRef<str>>(&'a self, parts: &'a [T]) -> Option<Cow<'_, str>> {
fn path_string<'a, T: AsRef<str>>(&'a self, parts: &'a [T]) -> Option<Cow<'a, str>> {
self.value.path_string(parts)
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.80"
channel = "1.82"
profile = "default"
2 changes: 1 addition & 1 deletion src/cli/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl Fmt {
format!("{}", heading.bold())
}

pub fn meta(meta: &String) -> String {
pub fn meta(meta: &str) -> String {
format!("{}", meta.yellow())
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/generator/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use derive_setters::Setters;
use path_clean::PathClean;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use tailcall_valid::{Valid, ValidateFrom, Validator};
use url::Url;

use crate::core::config::transformer::Preset;
use crate::core::config::{self};
use crate::core::http::Method;
use crate::core::valid::{Valid, ValidateFrom, Validator};

#[derive(Deserialize, Serialize, Debug, Default, Setters)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -268,9 +268,9 @@ mod tests {
use std::collections::HashMap;

use pretty_assertions::assert_eq;
use tailcall_valid::{ValidateInto, ValidationError, Validator};

use super::*;
use crate::core::valid::{ValidateInto, ValidationError, Validator};

fn location<S: AsRef<str>>(s: S) -> Location<UnResolved> {
Location(s.as_ref().to_string(), PhantomData)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::Path;
use http::header::{HeaderMap, HeaderName, HeaderValue};
use inquire::Confirm;
use pathdiff::diff_paths;
use tailcall_valid::{ValidateInto, Validator};

use super::config::{Config, LLMConfig, Resolved, Source};
use super::source::ConfigSource;
Expand All @@ -14,7 +15,6 @@ use crate::core::generator::{Generator as ConfigGenerator, Input};
use crate::core::proto_reader::ProtoReader;
use crate::core::resource_reader::{Resource, ResourceReader};
use crate::core::runtime::TargetRuntime;
use crate::core::valid::{ValidateInto, Validator};
use crate::core::{Mustache, Transform};

/// CLI that reads the the config file and generates the required tailcall
Expand Down
2 changes: 1 addition & 1 deletion src/core/async_graphql_hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl GraphQLArcResponse {
.collect::<Vec<u8>>();

// Wrap the result in square brackets
[&[b'['], &combined[..], &[b']']].concat()
[b"[", &combined[..], b"]"].concat()
}
JITBatchResponse::Single(resp) => resp.body.as_ref().to_owned(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::collections::HashSet;
use std::fmt::Debug;

use jsonwebtoken::jwk::JwkSet;
use tailcall_valid::Valid;

use crate::core::config::ConfigModule;
use crate::core::valid::Valid;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Basic {
Expand Down
34 changes: 26 additions & 8 deletions src/core/blueprint/cors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::fmt::Display;

use derive_setters::Setters;
use http::header;
use http::header::{HeaderName, HeaderValue};
use http::request::Parts;
use tailcall_valid::ValidationError;

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

#[derive(Clone, Debug, Setters, Default)]
pub struct Cors {
Expand Down Expand Up @@ -155,39 +157,55 @@ fn ensure_usable_cors_rules(layer: &Cors) -> Result<(), ValidationError<String>>
Ok(())
}

fn to_validation_err<T: Display>(err: T) -> ValidationError<String> {
ValidationError::new(err.to_string())
}

impl TryFrom<config::cors::Cors> for Cors {
type Error = ValidationError<String>;

fn try_from(value: config::cors::Cors) -> Result<Self, ValidationError<String>> {
let cors = Cors {
allow_credentials: value.allow_credentials.unwrap_or_default(),
allow_headers: (!value.allow_headers.is_empty())
.then_some(value.allow_headers.join(", ").parse()?),
allow_headers: (!value.allow_headers.is_empty()).then_some(
value
.allow_headers
.join(", ")
.parse()
.map_err(to_validation_err)?,
),
allow_methods: {
Some(if value.allow_methods.is_empty() {
"*".parse()?
"*".parse().map_err(to_validation_err)?
} else {
value
.allow_methods
.into_iter()
.map(|val| val.to_string())
.collect::<Vec<String>>()
.join(", ")
.parse()?
.parse()
.map_err(to_validation_err)?
})
},
allow_origins: value
.allow_origins
.into_iter()
.map(|val| Ok(val.parse()?))
.map(|val| val.parse().map_err(to_validation_err))
.collect::<Result<_, ValidationError<String>>>()?,
allow_private_network: value.allow_private_network.unwrap_or_default(),
expose_headers: Some(value.expose_headers.join(", ").parse()?),
expose_headers: Some(
value
.expose_headers
.join(", ")
.parse()
.map_err(to_validation_err)?,
),
max_age: value.max_age.map(|val| val.into()),
vary: value
.vary
.iter()
.map(|val| Ok(val.parse()?))
.map(|val| val.parse().map_err(to_validation_err))
.collect::<Result<_, ValidationError<String>>>()?,
};
ensure_usable_cors_rules(&cors)?;
Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use async_graphql_value::ConstValue;
use directive::Directive;
use interface_resolver::update_interface_resolver;
use regex::Regex;
use tailcall_valid::{Valid, Validator};
use union_resolver::update_union_resolver;

use crate::core::blueprint::*;
use crate::core::config::{Config, Enum, Field, GraphQLOperationType, Protected, Union};
use crate::core::directive::DirectiveCodec;
use crate::core::ir::model::{Cache, IR};
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, Validator};
use crate::core::{config, scalar, Type};

pub fn to_scalar_type_definition(name: &str) -> Valid<Definition, String> {
Expand Down Expand Up @@ -496,7 +496,7 @@ pub fn to_field_definition(
object_name: &str,
config_module: &ConfigModule,
type_of: &config::Type,
name: &String,
name: &str,
) -> Valid<FieldDefinition, String> {
update_args()
.and(update_http().trace(config::Http::trace_name().as_str()))
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::collections::HashMap;
use async_graphql::parser::types::ConstDirective;
use async_graphql::Name;
use serde_json::Value;
use tailcall_valid::{Valid, ValidationError, Validator};

use crate::core::valid::{Valid, ValidationError, Validator};
use crate::core::{config, pos};

#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/from_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::{BTreeMap, BTreeSet};

use async_graphql::dynamic::SchemaBuilder;
use indexmap::IndexMap;
use tailcall_valid::{Valid, ValidationError, Validator};

use self::telemetry::to_opentelemetry;
use super::Server;
Expand All @@ -12,7 +13,6 @@ use crate::core::config::{Arg, Batch, Config, ConfigModule};
use crate::core::ir::model::{IO, IR};
use crate::core::json::JsonSchema;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, ValidationError, Validator};
use crate::core::Type;

pub fn config_blueprint<'a>() -> TryFold<'a, ConfigModule, Blueprint, String> {
Expand Down
3 changes: 2 additions & 1 deletion src/core/blueprint/interface_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::BTreeSet;

use tailcall_valid::{Valid, Validator};

use crate::core::blueprint::FieldDefinition;
use crate::core::config::{ConfigModule, Discriminate, Field, Type};
use crate::core::ir::model::IR;
use crate::core::ir::Discriminator;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, Validator};

fn compile_interface_resolver(
interface_name: &str,
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/into_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use async_graphql::parser::types::{
};
use async_graphql::{Name, Positioned};
use async_graphql_value::ConstValue;
use tailcall_valid::Validator;

use super::blueprint;
use super::directive::{to_const_directive, Directive};
use crate::core::blueprint::{Blueprint, Definition};
use crate::core::pos;
use crate::core::valid::Validator;

fn to_directives(directives: &[Directive]) -> Vec<Positioned<ConstDirective>> {
directives
Expand Down
3 changes: 2 additions & 1 deletion src/core/blueprint/links.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use tailcall_valid::{Valid, ValidationError, Validator};

use crate::core::config::{Link, LinkType};
use crate::core::directive::DirectiveCodec;
use crate::core::valid::{Valid, ValidationError, Validator};

pub struct Links;

Expand Down
6 changes: 4 additions & 2 deletions src/core/blueprint/mustache.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use tailcall_valid::{Valid, Validator};

use super::FieldDefinition;
use crate::core::config::{self, Config};
use crate::core::ir::model::{IO, IR};
use crate::core::scalar;
use crate::core::valid::{Valid, Validator};

struct MustachePartsValidator<'a> {
type_of: &'a config::Type,
Expand Down Expand Up @@ -179,10 +180,11 @@ impl FieldDefinition {

#[cfg(test)]
mod test {
use tailcall_valid::Validator;

use super::MustachePartsValidator;
use crate::core::blueprint::{FieldDefinition, InputFieldDefinition};
use crate::core::config::{self, Config, Field};
use crate::core::valid::Validator;
use crate::core::Type;

fn initialize_test_config_and_field() -> (Config, FieldDefinition) {
Expand Down
Loading

0 comments on commit 68db95f

Please sign in to comment.