Skip to content

Commit 4a1920e

Browse files
mobley-trenttusharmathautofix-ci[bot]coderabbitai[bot]
authored
fix: type definitions in .tailcallrc.graphql (#1689)
Co-authored-by: Tushar Mathur <tusharmath@gmail.com> 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>
1 parent f89a888 commit 4a1920e

19 files changed

+62
-57
lines changed

generated/.tailcallrc.graphql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,20 +421,20 @@ input Apollo {
421421
"""
422422
Setting `platform` for Apollo.
423423
"""
424-
platform: String!
424+
platform: String
425425
"""
426426
Setting `userVersion` for Apollo.
427427
"""
428-
userVersion: String!
428+
userVersion: String
429429
"""
430430
Setting `version` for Apollo.
431431
"""
432-
version: String!
432+
version: String
433433
}
434434
input Batch {
435435
delay: Int!
436436
headers: [String!]
437-
maxSize: Int!
437+
maxSize: Int
438438
}
439439
"""
440440
The @cache operator enables caching for the query, field or type it is applied to.

generated/.tailcallrc.schema.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,24 @@
103103
},
104104
"platform": {
105105
"description": "Setting `platform` for Apollo.",
106-
"default": "platform",
107-
"type": "string"
106+
"type": [
107+
"string",
108+
"null"
109+
]
108110
},
109111
"userVersion": {
110112
"description": "Setting `userVersion` for Apollo.",
111-
"default": "1.0",
112-
"type": "string"
113+
"type": [
114+
"string",
115+
"null"
116+
]
113117
},
114118
"version": {
115119
"description": "Setting `version` for Apollo.",
116-
"default": "1.0",
117-
"type": "string"
120+
"type": [
121+
"string",
122+
"null"
123+
]
118124
}
119125
}
120126
},
@@ -170,8 +176,10 @@
170176
"uniqueItems": true
171177
},
172178
"maxSize": {
173-
"default": 100,
174-
"type": "integer",
179+
"type": [
180+
"integer",
181+
"null"
182+
],
175183
"format": "uint",
176184
"minimum": 0.0
177185
}

src/blueprint/upstream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct Upstream {
3232
impl Upstream {
3333
pub fn is_batching_enabled(&self) -> bool {
3434
if let Some(batch) = self.batch.as_ref() {
35-
batch.delay >= 1 || batch.max_size >= 1
35+
batch.delay >= 1 || batch.max_size.unwrap_or_default() >= 1
3636
} else {
3737
false
3838
}
@@ -88,7 +88,7 @@ fn get_batch(upstream: &config::Upstream) -> Valid<Option<Batch>, String> {
8888
|| Valid::succeed(None),
8989
|batch| {
9090
Valid::succeed(Some(Batch {
91-
max_size: (upstream).get_max_size(),
91+
max_size: Some((upstream).get_max_size()),
9292
delay: (upstream).get_delay(),
9393
headers: batch.headers.clone(),
9494
}))

src/cli/server/server_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ impl ServerConfig {
2828
let (graph_id, variant) = apollo.graph_ref.split_once('@').unwrap();
2929
extensions.push(SchemaExtension::new(ApolloTracing::new(
3030
apollo.api_key.clone(),
31-
apollo.platform.clone(),
31+
apollo.platform.clone().unwrap_or_default(),
3232
graph_id.to_string(),
3333
variant.to_string(),
34-
apollo.version.clone(),
34+
apollo.version.clone().unwrap_or_default(),
3535
)));
3636
}
3737
rt.add_extensions(extensions);

src/config/apollo.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

33
use crate::config::ConfigReaderContext;
4+
use crate::is_default;
45
use crate::mustache::Mustache;
56

67
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, schemars::JsonSchema)]
@@ -14,28 +15,16 @@ pub struct Apollo {
1415
pub graph_ref: String,
1516
///
1617
/// Setting `userVersion` for Apollo.
17-
#[serde(default = "default_user_version")]
18-
pub user_version: String,
18+
#[serde(default, skip_serializing_if = "is_default")]
19+
pub user_version: Option<String>,
1920
///
2021
/// Setting `platform` for Apollo.
21-
#[serde(default = "default_platform")]
22-
pub platform: String,
22+
#[serde(default, skip_serializing_if = "is_default")]
23+
pub platform: Option<String>,
2324
///
2425
/// Setting `version` for Apollo.
25-
#[serde(default = "default_version")]
26-
pub version: String,
27-
}
28-
29-
fn default_user_version() -> String {
30-
"1.0".to_string()
31-
}
32-
33-
fn default_platform() -> String {
34-
"platform".to_string()
35-
}
36-
37-
fn default_version() -> String {
38-
"1.0".to_string()
26+
#[serde(default, skip_serializing_if = "is_default")]
27+
pub version: Option<String>,
3928
}
4029

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

51-
let user_version_tmpl = Mustache::parse(user_version)?;
52-
*user_version = user_version_tmpl.render(reader_ctx);
40+
let user_version_tmpl = Mustache::parse(user_version.as_deref().unwrap_or_default())?;
41+
*user_version = Some(user_version_tmpl.render(reader_ctx));
5342

54-
let platform_tmpl = Mustache::parse(platform)?;
55-
*platform = platform_tmpl.render(reader_ctx);
43+
let platform_tmpl = Mustache::parse(platform.as_deref().unwrap_or_default())?;
44+
*platform = Some(platform_tmpl.render(reader_ctx));
5645

57-
let version_tmpl = Mustache::parse(version)?;
58-
*version = version_tmpl.render(reader_ctx);
46+
let version_tmpl = Mustache::parse(version.as_deref().unwrap_or_default())?;
47+
*version = Some(version_tmpl.render(reader_ctx));
5948

6049
Ok(())
6150
}

src/config/upstream.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@ use crate::is_default;
77
use crate::macros::MergeRight;
88
use crate::merge_right::MergeRight;
99

10+
const DEFAULT_MAX_SIZE: usize = 100;
11+
1012
#[derive(
1113
Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Setters, schemars::JsonSchema, MergeRight,
1214
)]
1315
#[serde(rename_all = "camelCase", default)]
1416
pub struct Batch {
1517
pub delay: usize,
1618
pub headers: BTreeSet<String>,
17-
pub max_size: usize,
19+
#[serde(default, skip_serializing_if = "is_default")]
20+
pub max_size: Option<usize>,
1821
}
19-
2022
impl Default for Batch {
2123
fn default() -> Self {
22-
Batch { max_size: 100, delay: 0, headers: BTreeSet::new() }
24+
Batch {
25+
max_size: Some(DEFAULT_MAX_SIZE),
26+
delay: 0,
27+
headers: BTreeSet::new(),
28+
}
2329
}
2430
}
2531

@@ -172,7 +178,9 @@ impl Upstream {
172178
}
173179

174180
pub fn get_max_size(&self) -> usize {
175-
self.batch.clone().unwrap_or_default().max_size
181+
self.batch
182+
.as_ref()
183+
.map_or(DEFAULT_MAX_SIZE, |b| b.max_size.unwrap_or(DEFAULT_MAX_SIZE))
176184
}
177185

178186
pub fn get_http_2_only(&self) -> bool {

src/graphql/data_loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl GraphqlDataLoader {
2424
pub fn to_data_loader(self, batch: Batch) -> DataLoader<DataLoaderRequest, GraphqlDataLoader> {
2525
DataLoader::new(self)
2626
.delay(Duration::from_millis(batch.delay as u64))
27-
.max_batch_size(batch.max_size)
27+
.max_batch_size(batch.max_size.unwrap_or_default())
2828
}
2929
}
3030

src/grpc/data_loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl GrpcDataLoader {
2929
pub fn to_data_loader(self, batch: Batch) -> DataLoader<DataLoaderRequest, GrpcDataLoader> {
3030
DataLoader::new(self)
3131
.delay(Duration::from_millis(batch.delay as u64))
32-
.max_batch_size(batch.max_size)
32+
.max_batch_size(batch.max_size.unwrap_or_default())
3333
}
3434

3535
async fn load_dedupe_only(

src/http/data_loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl HttpDataLoader {
5353
pub fn to_data_loader(self, batch: Batch) -> DataLoader<DataLoaderRequest, HttpDataLoader> {
5454
DataLoader::new(self)
5555
.delay(Duration::from_millis(batch.delay as u64))
56-
.max_batch_size(batch.max_size)
56+
.max_batch_size(batch.max_size.unwrap_or_default())
5757
}
5858
}
5959

tests/snapshots/execution_spec__batching-default.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
schema @server @upstream(baseURL: "http://jsonplaceholder.typicode.com", batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) {
5+
schema @server @upstream(baseURL: "http://jsonplaceholder.typicode.com", batch: {delay: 10, headers: []}, httpCache: true) {
66
query: Query
77
}
88

tests/snapshots/execution_spec__graphql-dataloader-batch-request.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
schema @server @upstream(batch: {delay: 1, headers: [], maxSize: 100}) {
5+
schema @server @upstream(batch: {delay: 1, headers: []}) {
66
query: Query
77
}
88

tests/snapshots/execution_spec__graphql-dataloader-no-batch-request.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
schema @server @upstream(batch: {delay: 1, headers: [], maxSize: 100}) {
5+
schema @server @upstream(batch: {delay: 1, headers: []}) {
66
query: Query
77
}
88

tests/snapshots/execution_spec__grpc-batch.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
5+
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: []}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
66
query: Query
77
}
88

tests/snapshots/execution_spec__grpc-error.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
5+
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: []}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
66
query: Query
77
}
88

tests/snapshots/execution_spec__grpc-override-url-from-upstream.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
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) {
5+
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) {
66
query: Query
77
}
88

tests/snapshots/execution_spec__grpc-simple.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: [], maxSize: 100}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
5+
schema @server(graphiql: true, port: 8000) @upstream(batch: {delay: 10, headers: []}, httpCache: true) @link(id: "news", src: "news.proto", type: Protobuf) {
66
query: Query
77
}
88

tests/snapshots/execution_spec__grpc-url-from-upstream.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
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) {
5+
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) {
66
query: Query
77
}
88

tests/snapshots/execution_spec__jsonplaceholder-call-post.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
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) {
5+
schema @server(graphiql: true, hostname: "0.0.0.0", port: 8000) @upstream(baseURL: "http://jsonplaceholder.typicode.com", batch: {delay: 100, headers: []}, httpCache: true) {
66
query: Query
77
}
88

tests/snapshots/execution_spec__test-enum-default.md_merged.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: tests/execution_spec.rs
33
expression: merged
44
---
5-
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) {
5+
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) {
66
query: Query
77
}
88

0 commit comments

Comments
 (0)