Skip to content

Commit

Permalink
Merge branch 'main' into migrate_retry
Browse files Browse the repository at this point in the history
  • Loading branch information
mehul-m-prajapati authored Dec 28, 2024
2 parents dec78fe + e3a6026 commit 55ddcfa
Show file tree
Hide file tree
Showing 528 changed files with 2,521 additions and 909 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ tailcall-valid = { workspace = true }
dashmap = "6.1.0"
urlencoding = "2.1.3"
tailcall-chunk = "0.3.0"
unicode-segmentation = "1.12.0"

# to build rquickjs bindings on systems without builtin bindings
[target.'cfg(all(target_os = "windows", target_arch = "x86"))'.dependencies]
Expand Down
5 changes: 0 additions & 5 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "RuntimeConfig",
"type": "object",
"required": [
"links"
],
"properties": {
"links": {
"description": "A list of all links in the schema.",
Expand All @@ -15,7 +12,6 @@
},
"server": {
"description": "Dictates how the server behaves and helps tune tailcall for all ingress requests. Features such as request batching, SSL, HTTP2 etc. can be configured here.",
"default": {},
"allOf": [
{
"$ref": "#/definitions/Server"
Expand All @@ -32,7 +28,6 @@
},
"upstream": {
"description": "Dictates how tailcall should handle upstream requests/responses. Tuning upstream can improve performance and reliability for connections.",
"default": {},
"allOf": [
{
"$ref": "#/definitions/Upstream"
Expand Down
5 changes: 3 additions & 2 deletions src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ pub struct RuntimeConfig {
/// Dictates how the server behaves and helps tune tailcall for all ingress
/// requests. Features such as request batching, SSL, HTTP2 etc. can be
/// configured here.
#[serde(default)]
#[serde(default, skip_serializing_if = "is_default")]
pub server: Server,

///
/// Dictates how tailcall should handle upstream requests/responses.
/// Tuning upstream can improve performance and reliability for connections.
#[serde(default)]
#[serde(default, skip_serializing_if = "is_default")]
pub upstream: Upstream,

///
/// A list of all links in the schema.
#[serde(default, skip_serializing_if = "is_default")]
pub links: Vec<Link>,

/// Enable [opentelemetry](https://opentelemetry.io) support
Expand Down
7 changes: 6 additions & 1 deletion src/core/config/transformer/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ impl Transform for Subgraph {
let key = Key { fields };

to_directive(key.to_directive()).map(|directive| {
ty.directives.push(directive);
// Prevent transformer to push the same directive multiple times
if !ty.directives.iter().any(|d| {
d.name == directive.name && d.arguments == directive.arguments
}) {
ty.directives.push(directive);
}
})
}
None => Valid::succeed(()),
Expand Down
72 changes: 62 additions & 10 deletions src/core/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt::Display;
use async_graphql::parser::types::*;
use async_graphql::Positioned;
use async_graphql_value::ConstValue;
use unicode_segmentation::UnicodeSegmentation;

use super::jit::Directive as JitDirective;
use super::json::JsonLikeOwned;
Expand All @@ -28,19 +29,35 @@ impl<'a> Iterator for LineBreaker<'a> {
return None;
}

let end_index = self
.string
.chars()
.skip(self.index + self.break_at)
.enumerate()
.find(|(_, ch)| ch.is_whitespace())
.map(|(index, _)| self.index + self.break_at + index + 1)
.unwrap_or(self.string.len());
let graphemes = self.string[self.index..].graphemes(true).peekable();
let mut iter = graphemes;
let mut current_len = 0;
let mut last_valid_index = self.index;

while let Some(grapheme) = iter.peek() {
let grapheme_len = grapheme.len();

if current_len + grapheme_len > self.break_at {
break;
}

iter.next();
current_len += grapheme_len;
last_valid_index += grapheme_len;
}

for grapheme in iter {
if grapheme.chars().any(|ch| ch.is_whitespace()) {
last_valid_index += grapheme.len();
break;
}
last_valid_index += grapheme.len();
}

let start_index = self.index;
self.index = end_index;
self.index = last_valid_index;

Some(&self.string[start_index..end_index])
Some(&self.string[start_index..self.index])
}
}

Expand Down Expand Up @@ -456,3 +473,38 @@ impl<'a, Input: JsonLikeOwned + Display> From<&'a JitDirective<Input>> for Direc
}
}
}

#[cfg(test)]
mod tests {
use super::get_formatted_docs;

#[test]
fn test_get_formatted_docs() {
let input = Some(String::from(
"This is a test string for get_formatted_docs function. You are typing a long sentence for testing. What a nice, long sentence!",
));
let indent = 4;

let result = get_formatted_docs(input, indent);
let expected = String::from(
" \"\"\"\n This is a test string for get_formatted_docs function. You are typing a long sentence \n for testing. What a nice, long sentence!\n \"\"\"\n",
);

assert_eq!(result, expected)
}

#[test]
fn test_get_formatted_docs_utf8() {
let input = Some(String::from(
"get_formatted_docs 함수 테스트를 위한 문장입니다. 테스트를 위해 긴 문장을 입력하는 중 입니다. テストのために長い文章を入力しているところです。なんて素敵な長文です!",
));
let indent = 4;

let result = get_formatted_docs(input, indent);
let expected = String::from(
" \"\"\"\n get_formatted_docs 함수 테스트를 위한 문장입니다. 테스트를 위해 \n 긴 문장을 입력하는 중 입니다. テストのために長い文章を入力しているところです。なんて素敵な長文です!\n \"\"\"\n",
);

assert_eq!(result, expected)
}
}
24 changes: 17 additions & 7 deletions tests/core/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use tailcall::cli::javascript;
use tailcall::core::app_context::AppContext;
use tailcall::core::blueprint::Blueprint;
use tailcall::core::cache::InMemoryCache;
use tailcall::core::config::{ConfigModule, Source};
use tailcall::core::config::{ConfigModule, Link, RuntimeConfig, Source};
use tailcall::core::merge_right::MergeRight;
use tailcall::core::runtime::TargetRuntime;
use tailcall::core::worker::{Command, Event};
use tailcall::core::{EnvIO, WorkerIO};
Expand Down Expand Up @@ -51,14 +52,15 @@ impl ExecutionSpec {
.peekable();

let mut name: Option<String> = None;
let mut server: Vec<(Source, String)> = Vec::with_capacity(2);
let mut config = RuntimeConfig::default();
let mut mock: Option<Vec<Mock>> = None;
let mut env: Option<HashMap<String, String>> = None;
let mut files: BTreeMap<String, String> = BTreeMap::new();
let mut test: Option<Vec<APIRequest>> = None;
let mut runner: Option<Annotation> = None;
let mut check_identity = false;
let mut sdl_error = false;
let mut links_counter = 0;

while let Some(node) = children.next() {
match node {
Expand Down Expand Up @@ -172,8 +174,16 @@ impl ExecutionSpec {

match name {
"config" => {
// Server configs are only parsed if the test isn't skipped.
server.push((source, content));
config = config.merge_right(
RuntimeConfig::from_source(source, &content).unwrap(),
);
}
"schema" => {
// Schemas configs are only parsed if the test isn't skipped.
let name = format!("schema_{}.graphql", links_counter);
files.insert(name.clone(), content);
config.links.push(Link { src: name, ..Default::default() });
links_counter += 1;
}
"mock" => {
if mock.is_none() {
Expand Down Expand Up @@ -240,9 +250,9 @@ impl ExecutionSpec {
}
}

if server.is_empty() {
if links_counter == 0 {
return Err(anyhow!(
"Unexpected blocks in {:?}: You must define a GraphQL Config in an execution test.",
"Unexpected blocks in {:?}: You must define a GraphQL Schema in an execution test.",
path,
));
}
Expand All @@ -252,7 +262,7 @@ impl ExecutionSpec {
name: name.unwrap_or_else(|| path.file_name().unwrap().to_str().unwrap().to_string()),
safe_name: path.file_name().unwrap().to_str().unwrap().to_string(),

server,
config,
mock,
env,
test,
Expand Down
4 changes: 2 additions & 2 deletions tests/core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use derive_setters::Setters;
use tailcall::cli::javascript::init_worker_io;
use tailcall::core::blueprint::Script;
use tailcall::core::cache::InMemoryCache;
use tailcall::core::config::Source;
use tailcall::core::config::RuntimeConfig;
use tailcall::core::runtime::TargetRuntime;
use tailcall::core::worker::{Command, Event};

Expand All @@ -25,7 +25,7 @@ pub struct ExecutionSpec {
pub name: String,
pub safe_name: String,

pub server: Vec<(Source, String)>,
pub config: RuntimeConfig,
pub mock: Option<Vec<Mock>>,
pub env: Option<HashMap<String, String>>,
pub test: Option<Vec<APIRequest>>,
Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/add-field-index-list.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server @upstream {
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/add-field-many-list.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server @upstream {
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/add-field-many.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server @upstream {
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/add-field-modify.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server @upstream {
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server @upstream {
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/add-field-with-modify.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server @upstream {
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/add-field.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server @upstream {
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server(enableFederation: true, port: 8000) @upstream(batch: {delay: 100, headers: []}, httpCache: 42) {
schema
@server(enableFederation: true, port: 8000)
@upstream(batch: {delay: 100, headers: []}, httpCache: 42)
@link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ snapshot_kind: text
schema
@server(enableFederation: true, port: 8000)
@upstream(batch: {delay: 100, headers: []}, httpCache: 42)
@link(src: "./posts.graphql", type: Config) {
@link(src: "./posts.graphql", type: Config)
@link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/apollo-tracing.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server(hostname: "0.0.0.0", port: 8000) @upstream {
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/async-cache-disabled.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server(port: 8000, queryValidation: false) @upstream {
schema @server(port: 8000, queryValidation: false) @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server(port: 8000, queryValidation: false) @upstream {
schema @server(port: 8000, queryValidation: false) @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/async-cache-enabled.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server(port: 8000, queryValidation: false) @upstream {
schema @server(port: 8000, queryValidation: false) @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/async-cache-global.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server(port: 8000, queryValidation: false) @upstream {
schema @server(port: 8000, queryValidation: false) @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server(port: 8000, queryValidation: false) @upstream {
schema @server(port: 8000, queryValidation: false) @upstream @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
Loading

0 comments on commit 55ddcfa

Please sign in to comment.