Skip to content

Commit 9d6d2bc

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/runtime-config-example
2 parents b30ec38 + e3a6026 commit 9d6d2bc

File tree

528 files changed

+2521
-909
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

528 files changed

+2521
-909
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ tailcall-valid = { workspace = true }
175175
dashmap = "6.1.0"
176176
urlencoding = "2.1.3"
177177
tailcall-chunk = "0.3.0"
178+
unicode-segmentation = "1.12.0"
178179

179180
# to build rquickjs bindings on systems without builtin bindings
180181
[target.'cfg(all(target_os = "windows", target_arch = "x86"))'.dependencies]

generated/.tailcallrc.schema.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "RuntimeConfig",
44
"type": "object",
5-
"required": [
6-
"links"
7-
],
85
"properties": {
96
"links": {
107
"description": "A list of all links in the schema.",
@@ -15,7 +12,6 @@
1512
},
1613
"server": {
1714
"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.",
18-
"default": {},
1915
"allOf": [
2016
{
2117
"$ref": "#/definitions/Server"
@@ -32,7 +28,6 @@
3228
},
3329
"upstream": {
3430
"description": "Dictates how tailcall should handle upstream requests/responses. Tuning upstream can improve performance and reliability for connections.",
35-
"default": {},
3631
"allOf": [
3732
{
3833
"$ref": "#/definitions/Upstream"

src/core/config/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ pub struct RuntimeConfig {
4343
/// Dictates how the server behaves and helps tune tailcall for all ingress
4444
/// requests. Features such as request batching, SSL, HTTP2 etc. can be
4545
/// configured here.
46-
#[serde(default)]
46+
#[serde(default, skip_serializing_if = "is_default")]
4747
pub server: Server,
4848

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

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

5960
/// Enable [opentelemetry](https://opentelemetry.io) support

src/core/config/transformer/subgraph.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ impl Transform for Subgraph {
5959
let key = Key { fields };
6060

6161
to_directive(key.to_directive()).map(|directive| {
62-
ty.directives.push(directive);
62+
// Prevent transformer to push the same directive multiple times
63+
if !ty.directives.iter().any(|d| {
64+
d.name == directive.name && d.arguments == directive.arguments
65+
}) {
66+
ty.directives.push(directive);
67+
}
6368
})
6469
}
6570
None => Valid::succeed(()),

src/core/document.rs

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fmt::Display;
44
use async_graphql::parser::types::*;
55
use async_graphql::Positioned;
66
use async_graphql_value::ConstValue;
7+
use unicode_segmentation::UnicodeSegmentation;
78

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

31-
let end_index = self
32-
.string
33-
.chars()
34-
.skip(self.index + self.break_at)
35-
.enumerate()
36-
.find(|(_, ch)| ch.is_whitespace())
37-
.map(|(index, _)| self.index + self.break_at + index + 1)
38-
.unwrap_or(self.string.len());
32+
let graphemes = self.string[self.index..].graphemes(true).peekable();
33+
let mut iter = graphemes;
34+
let mut current_len = 0;
35+
let mut last_valid_index = self.index;
36+
37+
while let Some(grapheme) = iter.peek() {
38+
let grapheme_len = grapheme.len();
39+
40+
if current_len + grapheme_len > self.break_at {
41+
break;
42+
}
43+
44+
iter.next();
45+
current_len += grapheme_len;
46+
last_valid_index += grapheme_len;
47+
}
48+
49+
for grapheme in iter {
50+
if grapheme.chars().any(|ch| ch.is_whitespace()) {
51+
last_valid_index += grapheme.len();
52+
break;
53+
}
54+
last_valid_index += grapheme.len();
55+
}
3956

4057
let start_index = self.index;
41-
self.index = end_index;
58+
self.index = last_valid_index;
4259

43-
Some(&self.string[start_index..end_index])
60+
Some(&self.string[start_index..self.index])
4461
}
4562
}
4663

@@ -456,3 +473,38 @@ impl<'a, Input: JsonLikeOwned + Display> From<&'a JitDirective<Input>> for Direc
456473
}
457474
}
458475
}
476+
477+
#[cfg(test)]
478+
mod tests {
479+
use super::get_formatted_docs;
480+
481+
#[test]
482+
fn test_get_formatted_docs() {
483+
let input = Some(String::from(
484+
"This is a test string for get_formatted_docs function. You are typing a long sentence for testing. What a nice, long sentence!",
485+
));
486+
let indent = 4;
487+
488+
let result = get_formatted_docs(input, indent);
489+
let expected = String::from(
490+
" \"\"\"\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",
491+
);
492+
493+
assert_eq!(result, expected)
494+
}
495+
496+
#[test]
497+
fn test_get_formatted_docs_utf8() {
498+
let input = Some(String::from(
499+
"get_formatted_docs 함수 테스트를 위한 문장입니다. 테스트를 위해 긴 문장을 입력하는 중 입니다. テストのために長い文章を入力しているところです。なんて素敵な長文です!",
500+
));
501+
let indent = 4;
502+
503+
let result = get_formatted_docs(input, indent);
504+
let expected = String::from(
505+
" \"\"\"\n get_formatted_docs 함수 테스트를 위한 문장입니다. 테스트를 위해 \n 긴 문장을 입력하는 중 입니다. テストのために長い文章を入力しているところです。なんて素敵な長文です!\n \"\"\"\n",
506+
);
507+
508+
assert_eq!(result, expected)
509+
}
510+
}

tests/core/parse.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use tailcall::cli::javascript;
1515
use tailcall::core::app_context::AppContext;
1616
use tailcall::core::blueprint::Blueprint;
1717
use tailcall::core::cache::InMemoryCache;
18-
use tailcall::core::config::{ConfigModule, Source};
18+
use tailcall::core::config::{ConfigModule, Link, RuntimeConfig, Source};
19+
use tailcall::core::merge_right::MergeRight;
1920
use tailcall::core::runtime::TargetRuntime;
2021
use tailcall::core::worker::{Command, Event};
2122
use tailcall::core::{EnvIO, WorkerIO};
@@ -51,14 +52,15 @@ impl ExecutionSpec {
5152
.peekable();
5253

5354
let mut name: Option<String> = None;
54-
let mut server: Vec<(Source, String)> = Vec::with_capacity(2);
55+
let mut config = RuntimeConfig::default();
5556
let mut mock: Option<Vec<Mock>> = None;
5657
let mut env: Option<HashMap<String, String>> = None;
5758
let mut files: BTreeMap<String, String> = BTreeMap::new();
5859
let mut test: Option<Vec<APIRequest>> = None;
5960
let mut runner: Option<Annotation> = None;
6061
let mut check_identity = false;
6162
let mut sdl_error = false;
63+
let mut links_counter = 0;
6264

6365
while let Some(node) = children.next() {
6466
match node {
@@ -172,8 +174,16 @@ impl ExecutionSpec {
172174

173175
match name {
174176
"config" => {
175-
// Server configs are only parsed if the test isn't skipped.
176-
server.push((source, content));
177+
config = config.merge_right(
178+
RuntimeConfig::from_source(source, &content).unwrap(),
179+
);
180+
}
181+
"schema" => {
182+
// Schemas configs are only parsed if the test isn't skipped.
183+
let name = format!("schema_{}.graphql", links_counter);
184+
files.insert(name.clone(), content);
185+
config.links.push(Link { src: name, ..Default::default() });
186+
links_counter += 1;
177187
}
178188
"mock" => {
179189
if mock.is_none() {
@@ -240,9 +250,9 @@ impl ExecutionSpec {
240250
}
241251
}
242252

243-
if server.is_empty() {
253+
if links_counter == 0 {
244254
return Err(anyhow!(
245-
"Unexpected blocks in {:?}: You must define a GraphQL Config in an execution test.",
255+
"Unexpected blocks in {:?}: You must define a GraphQL Schema in an execution test.",
246256
path,
247257
));
248258
}
@@ -252,7 +262,7 @@ impl ExecutionSpec {
252262
name: name.unwrap_or_else(|| path.file_name().unwrap().to_str().unwrap().to_string()),
253263
safe_name: path.file_name().unwrap().to_str().unwrap().to_string(),
254264

255-
server,
265+
config,
256266
mock,
257267
env,
258268
test,

tests/core/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use derive_setters::Setters;
1010
use tailcall::cli::javascript::init_worker_io;
1111
use tailcall::core::blueprint::Script;
1212
use tailcall::core::cache::InMemoryCache;
13-
use tailcall::core::config::Source;
13+
use tailcall::core::config::RuntimeConfig;
1414
use tailcall::core::runtime::TargetRuntime;
1515
use tailcall::core::worker::{Command, Event};
1616

@@ -25,7 +25,7 @@ pub struct ExecutionSpec {
2525
pub name: String,
2626
pub safe_name: String,
2727

28-
pub server: Vec<(Source, String)>,
28+
pub config: RuntimeConfig,
2929
pub mock: Option<Vec<Mock>>,
3030
pub env: Option<HashMap<String, String>>,
3131
pub test: Option<Vec<APIRequest>>,

tests/core/snapshots/add-field-index-list.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ source: tests/core/spec.rs
33
expression: formatter
44
snapshot_kind: text
55
---
6-
schema @server @upstream {
6+
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
77
query: Query
88
}
99

tests/core/snapshots/add-field-many-list.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ source: tests/core/spec.rs
33
expression: formatter
44
snapshot_kind: text
55
---
6-
schema @server @upstream {
6+
schema @server @upstream @link(src: "schema_0.graphql", type: Config) {
77
query: Query
88
}
99

0 commit comments

Comments
 (0)