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

fix: type definitions in .tailcallrc.graphql #1689

Merged
merged 38 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6f01a2e
Initial commit
mobley-trent Apr 10, 2024
e9ad444
Updated data_loader.rs
mobley-trent Apr 10, 2024
ef1192b
Serde default for maxSize
mobley-trent Apr 11, 2024
35b287e
Merge branch 'main' of https://github.com/tailcallhq/tailcall into gr…
mobley-trent Apr 11, 2024
96a20d6
Updated Apollo params to Option
mobley-trent Apr 12, 2024
458bcbc
Merge branch 'main' of https://github.com/tailcallhq/tailcall into gr…
mobley-trent Apr 12, 2024
6a9e996
Removing 100 as the default max size
mobley-trent Apr 12, 2024
9bfe8ad
Merge branch 'main' of https://github.com/tailcallhq/tailcall into gr…
mobley-trent Apr 12, 2024
ee53a7b
Removed asset image from PR
mobley-trent Apr 12, 2024
a8ca7b7
Merge branch 'main' of https://github.com/tailcallhq/tailcall into gr…
mobley-trent Apr 15, 2024
867883f
Merge branch 'main' into graphql_fix
tusharmath Apr 15, 2024
656b0e2
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 15, 2024
cd0df15
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Apr 15, 2024
594ba60
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Apr 15, 2024
b509cfe
Merge branch 'main' into graphql_fix
mobley-trent Apr 15, 2024
2f2bcec
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 15, 2024
b90868d
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Apr 15, 2024
7ff6e90
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Apr 15, 2024
8ee651c
Fixed failing test
mobley-trent Apr 15, 2024
db9a26e
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 15, 2024
fb68a81
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Apr 15, 2024
8d89f14
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Apr 15, 2024
7a7386b
Revert changes made in commit 8ee651cb96d5711eaeb9cb85587509674c1273c0
mobley-trent Apr 15, 2024
d7171bd
Merge branch 'graphql_fix' of https://github.com/mobley-trent/tailcal…
mobley-trent Apr 15, 2024
152206f
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 15, 2024
770073a
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Apr 15, 2024
c7b483f
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Apr 15, 2024
8ee89ee
Fixed failing tests
mobley-trent Apr 15, 2024
144edb6
Adding the error messages from failing tests
mobley-trent Apr 15, 2024
64a2d99
Update tests/execution/grpc-batch.md
mobley-trent Apr 16, 2024
96bcefd
Update tests/execution/batching-default.md
mobley-trent Apr 16, 2024
58edee8
prettier fix
mobley-trent Apr 16, 2024
4834523
Merge branch 'main' of https://github.com/tailcallhq/tailcall into gr…
mobley-trent Apr 16, 2024
adb283e
Fixed failing tests
mobley-trent Apr 16, 2024
0a6e5f6
prettier fix
mobley-trent Apr 16, 2024
e976623
Updated upstream.rs - const value for Batch::maxSize
mobley-trent Apr 16, 2024
36ba802
Updated upstream.rs - removed clone from batch in get_max_size
mobley-trent Apr 17, 2024
e05da9d
Updated upstream.rs - Linitng, map_or
mobley-trent Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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(),

Check warning on line 31 in src/cli/server/server_config.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/server_config.rs#L31

Added line #L31 was not covered by tests
graph_id.to_string(),
variant.to_string(),
apollo.version.clone(),
apollo.version.clone().unwrap_or_default(),

Check warning on line 34 in src/cli/server/server_config.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/server_config.rs#L34

Added line #L34 was not covered by tests
)));
}
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));
mobley-trent marked this conversation as resolved.
Show resolved Hide resolved

Ok(())
}
Expand Down
12 changes: 8 additions & 4 deletions src/config/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use crate::merge_right::MergeRight;
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(100), delay: 0, headers: BTreeSet::new() }
mobley-trent marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -166,7 +166,11 @@ impl Upstream {
}

pub fn get_max_size(&self) -> usize {
self.batch.clone().unwrap_or_default().max_size
self.batch
.clone()
.unwrap_or_default()
.max_size
.unwrap_or_default()
}

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
3 changes: 3 additions & 0 deletions tests/execution/batching-default.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Batching default

##### skip
mobley-trent marked this conversation as resolved.
Show resolved Hide resolved
[//]: # "Validation Error: GroupBy can only be applied if batching is enabled [Post, user, @http]"

mobley-trent marked this conversation as resolved.
Show resolved Hide resolved
```graphql @server
schema @server @upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: true, batch: {delay: 10}) {
query: Query
Expand Down
3 changes: 3 additions & 0 deletions tests/execution/graphql-dataloader-batch-request.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Graphql datasource

##### skip
[//]: # "IOException: No mock found for request: POST http://upstream/graphql in tests/execution/graphql-dataloader-batch-request.md"

mobley-trent marked this conversation as resolved.
Show resolved Hide resolved
```graphql @server
schema @upstream(batch: {delay: 1}) {
query: Query
Expand Down
4 changes: 4 additions & 0 deletions tests/execution/grpc-batch.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Grpc datasource with batching

##### skip
tusharmath marked this conversation as resolved.
Show resolved Hide resolved

[//]: # "failed: expected mock for http://localhost:50051/news.NewsService/GetMultipleNews to be hit exactly 1 times, but it was hit 2 times for grpc-batch.md"
mobley-trent marked this conversation as resolved.
Show resolved Hide resolved

mobley-trent marked this conversation as resolved.
Show resolved Hide resolved
```protobuf @file:news.proto
syntax = "proto3";

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 @@ -11,5 +11,14 @@ expression: errors
"@http"
],
"description": null
},
{
"message": "GroupBy can only be applied if batching is enabled",
"trace": [
"Query",
"user",
"@http"
],
"description": null
}
]
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
Loading