Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate to runtime config #3229

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
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
6 changes: 5 additions & 1 deletion tests/core/snapshots/auth-basic.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server(port: 8000) @upstream @link(id: "htpasswd", src: ".htpasswd", type: Htpasswd) {
schema
@server(port: 8000)
@upstream
@link(id: "htpasswd", src: ".htpasswd", type: Htpasswd)
@link(src: "schema_0.graphql", type: Config) {
query: Query
mutation: Mutation
}
Expand Down
6 changes: 5 additions & 1 deletion tests/core/snapshots/auth-jwt.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server(port: 8000) @upstream @link(id: "jwks", src: "jwks.json", type: Jwks) {
schema
@server(port: 8000)
@upstream
@link(id: "jwks", src: "jwks.json", type: Jwks)
@link(src: "schema_0.graphql", type: Config) {
query: Query
mutation: Mutation
}
Expand Down
3 changes: 2 additions & 1 deletion tests/core/snapshots/auth-multiple-complex.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ schema
@upstream
@link(id: "a", src: ".htpasswd_a", type: Htpasswd)
@link(id: "b", src: ".htpasswd_b", type: Htpasswd)
@link(id: "c", src: ".htpasswd_c", type: Htpasswd) {
@link(id: "c", src: ".htpasswd_c", type: Htpasswd)
@link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
3 changes: 2 additions & 1 deletion tests/core/snapshots/auth-multiple.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ schema
@upstream
@link(id: "a", src: ".htpasswd_a", type: Htpasswd)
@link(id: "b", src: ".htpasswd_b", type: Htpasswd)
@link(id: "c", src: ".htpasswd_c", type: Htpasswd) {
@link(id: "c", src: ".htpasswd_c", type: Htpasswd)
@link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
3 changes: 2 additions & 1 deletion tests/core/snapshots/auth.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ schema
@server
@upstream
@link(id: "htpasswd", src: ".htpasswd", type: Htpasswd)
@link(id: "jwks", src: "jwks.json", type: Jwks) {
@link(id: "jwks", src: "jwks.json", type: Jwks)
@link(src: "schema_0.graphql", type: Config) {
query: Query
}

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

Expand Down
2 changes: 1 addition & 1 deletion tests/core/snapshots/batching-default.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(batch: {delay: 10, headers: []}, httpCache: 42) {
schema @server @upstream(batch: {delay: 10, headers: []}, httpCache: 42) @link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
5 changes: 4 additions & 1 deletion tests/core/snapshots/batching-disabled.md_merged.snap
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 @upstream(batch: {delay: 0, headers: [], maxSize: 100}, httpCache: 42) {
schema
@server
@upstream(batch: {delay: 0, headers: [], maxSize: 100}, 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 @@ -3,7 +3,10 @@ source: tests/core/spec.rs
expression: formatter
snapshot_kind: text
---
schema @server @upstream(batch: {delay: 1, headers: [], maxSize: 1000}, httpCache: 42) {
schema
@server
@upstream(batch: {delay: 1, headers: [], maxSize: 1000}, 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 @@ -5,7 +5,8 @@ snapshot_kind: text
---
schema
@server(port: 8000, queryValidation: false)
@upstream(batch: {delay: 1, headers: [], maxSize: 1000}, httpCache: 42) {
@upstream(batch: {delay: 1, headers: [], maxSize: 1000}, httpCache: 42)
@link(src: "schema_0.graphql", type: Config) {
query: Query
}

Expand Down
Loading
Loading