Skip to content

Commit

Permalink
fix: type definitions in .tailcallrc.graphql (#1689)
Browse files Browse the repository at this point in the history
Co-authored-by: Tushar Mathur <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored and ssddOnTop committed May 2, 2024
1 parent 74d3f8e commit e180795
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 57 deletions.
8 changes: 4 additions & 4 deletions generated/.tailcallrc.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -421,20 +421,20 @@ input Apollo {
"""
Setting `platform` for Apollo.
"""
platform: String!
platform: String
"""
Setting `userVersion` for Apollo.
"""
userVersion: String!
userVersion: String
"""
Setting `version` for Apollo.
"""
version: String!
version: String
}
input Batch {
delay: Int!
headers: [String!]
maxSize: Int!
maxSize: Int
}
"""
The @cache operator enables caching for the query, field or type it is applied to.
Expand Down
24 changes: 16 additions & 8 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,24 @@
},
"platform": {
"description": "Setting `platform` for Apollo.",
"default": "platform",
"type": "string"
"type": [
"string",
"null"
]
},
"userVersion": {
"description": "Setting `userVersion` for Apollo.",
"default": "1.0",
"type": "string"
"type": [
"string",
"null"
]
},
"version": {
"description": "Setting `version` for Apollo.",
"default": "1.0",
"type": "string"
"type": [
"string",
"null"
]
}
}
},
Expand Down Expand Up @@ -170,8 +176,10 @@
"uniqueItems": true
},
"maxSize": {
"default": 100,
"type": "integer",
"type": [
"integer",
"null"
],
"format": "uint",
"minimum": 0.0
}
Expand Down
4 changes: 2 additions & 2 deletions src/blueprint/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Upstream {
impl Upstream {
pub fn is_batching_enabled(&self) -> bool {
if let Some(batch) = self.batch.as_ref() {
batch.delay >= 1 || batch.max_size >= 1
batch.delay >= 1 || batch.max_size.unwrap_or_default() >= 1
} else {
false
}
Expand Down Expand Up @@ -88,7 +88,7 @@ fn get_batch(upstream: &config::Upstream) -> Valid<Option<Batch>, String> {
|| Valid::succeed(None),
|batch| {
Valid::succeed(Some(Batch {
max_size: (upstream).get_max_size(),
max_size: Some((upstream).get_max_size()),
delay: (upstream).get_delay(),
headers: batch.headers.clone(),
}))
Expand Down
4 changes: 2 additions & 2 deletions src/cli/server/server_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ impl ServerConfig {
let (graph_id, variant) = apollo.graph_ref.split_once('@').unwrap();
extensions.push(SchemaExtension::new(ApolloTracing::new(
apollo.api_key.clone(),
apollo.platform.clone(),
apollo.platform.clone().unwrap_or_default(),
graph_id.to_string(),
variant.to_string(),
apollo.version.clone(),
apollo.version.clone().unwrap_or_default(),
)));
}
rt.add_extensions(extensions);
Expand Down
37 changes: 13 additions & 24 deletions src/config/apollo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};

use crate::config::ConfigReaderContext;
use crate::is_default;
use crate::mustache::Mustache;

#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, schemars::JsonSchema)]
Expand All @@ -14,28 +15,16 @@ pub struct Apollo {
pub graph_ref: String,
///
/// Setting `userVersion` for Apollo.
#[serde(default = "default_user_version")]
pub user_version: String,
#[serde(default, skip_serializing_if = "is_default")]
pub user_version: Option<String>,
///
/// Setting `platform` for Apollo.
#[serde(default = "default_platform")]
pub platform: String,
#[serde(default, skip_serializing_if = "is_default")]
pub platform: Option<String>,
///
/// Setting `version` for Apollo.
#[serde(default = "default_version")]
pub version: String,
}

fn default_user_version() -> String {
"1.0".to_string()
}

fn default_platform() -> String {
"platform".to_string()
}

fn default_version() -> String {
"1.0".to_string()
#[serde(default, skip_serializing_if = "is_default")]
pub version: Option<String>,
}

impl Apollo {
Expand All @@ -48,14 +37,14 @@ impl Apollo {
let graph_ref_tmpl = Mustache::parse(graph_ref)?;
*graph_ref = graph_ref_tmpl.render(reader_ctx);

let user_version_tmpl = Mustache::parse(user_version)?;
*user_version = user_version_tmpl.render(reader_ctx);
let user_version_tmpl = Mustache::parse(user_version.as_deref().unwrap_or_default())?;
*user_version = Some(user_version_tmpl.render(reader_ctx));

let platform_tmpl = Mustache::parse(platform)?;
*platform = platform_tmpl.render(reader_ctx);
let platform_tmpl = Mustache::parse(platform.as_deref().unwrap_or_default())?;
*platform = Some(platform_tmpl.render(reader_ctx));

let version_tmpl = Mustache::parse(version)?;
*version = version_tmpl.render(reader_ctx);
let version_tmpl = Mustache::parse(version.as_deref().unwrap_or_default())?;
*version = Some(version_tmpl.render(reader_ctx));

Ok(())
}
Expand Down
16 changes: 12 additions & 4 deletions src/config/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ use crate::is_default;
use crate::macros::MergeRight;
use crate::merge_right::MergeRight;

const DEFAULT_MAX_SIZE: usize = 100;

#[derive(
Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Setters, schemars::JsonSchema, MergeRight,
)]
#[serde(rename_all = "camelCase", default)]
pub struct Batch {
pub delay: usize,
pub headers: BTreeSet<String>,
pub max_size: usize,
#[serde(default, skip_serializing_if = "is_default")]
pub max_size: Option<usize>,
}

impl Default for Batch {
fn default() -> Self {
Batch { max_size: 100, delay: 0, headers: BTreeSet::new() }
Batch {
max_size: Some(DEFAULT_MAX_SIZE),
delay: 0,
headers: BTreeSet::new(),
}
}
}

Expand Down Expand Up @@ -172,7 +178,9 @@ impl Upstream {
}

pub fn get_max_size(&self) -> usize {
self.batch.clone().unwrap_or_default().max_size
self.batch
.as_ref()
.map_or(DEFAULT_MAX_SIZE, |b| b.max_size.unwrap_or(DEFAULT_MAX_SIZE))
}

pub fn get_http_2_only(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/data_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl GraphqlDataLoader {
pub fn to_data_loader(self, batch: Batch) -> DataLoader<DataLoaderRequest, GraphqlDataLoader> {
DataLoader::new(self)
.delay(Duration::from_millis(batch.delay as u64))
.max_batch_size(batch.max_size)
.max_batch_size(batch.max_size.unwrap_or_default())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/grpc/data_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl GrpcDataLoader {
pub fn to_data_loader(self, batch: Batch) -> DataLoader<DataLoaderRequest, GrpcDataLoader> {
DataLoader::new(self)
.delay(Duration::from_millis(batch.delay as u64))
.max_batch_size(batch.max_size)
.max_batch_size(batch.max_size.unwrap_or_default())
}

async fn load_dedupe_only(
Expand Down
2 changes: 1 addition & 1 deletion src/http/data_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl HttpDataLoader {
pub fn to_data_loader(self, batch: Batch) -> DataLoader<DataLoaderRequest, HttpDataLoader> {
DataLoader::new(self)
.delay(Duration::from_millis(batch.delay as u64))
.max_batch_size(batch.max_size)
.max_batch_size(batch.max_size.unwrap_or_default())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server @upstream(baseURL: "http://jsonplaceholder.typicode.com", batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) {
schema @server @upstream(baseURL: "http://jsonplaceholder.typicode.com", batch: {delay: 10, headers: []}, httpCache: true) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server @upstream(batch: {delay: 1, headers: [], maxSize: 100}) {
schema @server @upstream(batch: {delay: 1, headers: []}) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server @upstream(batch: {delay: 1, headers: [], maxSize: 100}) {
schema @server @upstream(batch: {delay: 1, headers: []}) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/execution_spec__grpc-batch.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: []}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/execution_spec__grpc-error.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: []}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server(graphiql: true, port: 8000) @upstream(baseURL: "http://not-a-valid-grpc-url.com", batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
schema @server(graphiql: true, port: 8000) @upstream(baseURL: "http://not-a-valid-grpc-url.com", batch: {delay: 10, headers: []}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
query: Query
}

Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/execution_spec__grpc-simple.md_merged.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: []}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server(graphiql: true, port: 8000) @upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
schema @server(graphiql: true, port: 8000) @upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: []}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server(graphiql: true, hostname: "0.0.0.0", port: 8000) @upstream(baseURL: "http://jsonplaceholder.typicode.com", batch: {delay: 100, headers: [], maxSize: 100}, httpCache: true) {
schema @server(graphiql: true, hostname: "0.0.0.0", port: 8000) @upstream(baseURL: "http://jsonplaceholder.typicode.com", batch: {delay: 100, headers: []}, httpCache: true) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/execution_spec.rs
expression: merged
---
schema @server(graphiql: true, port: 8080) @upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "news", src: "./service.proto", type: Protobuf) {
schema @server(graphiql: true, port: 8080) @upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: []}, httpCache: true) @link(id: "news", src: "./service.proto", type: Protobuf) {
query: Query
}

Expand Down

0 comments on commit e180795

Please sign in to comment.