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

refactor: update upstream #2833

Closed
wants to merge 9 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions benches/impl_path_string_for_evaluation_context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::sync::Arc;
use std::sync::{Arc, RwLock};
use std::time::Duration;

use async_graphql::{Name, Value};
Expand Down Expand Up @@ -258,7 +258,8 @@ fn request_context() -> RequestContext {
}

pub fn bench_main(c: &mut Criterion) {
let mut req_ctx = request_context().allowed_headers(TEST_HEADERS.clone());
let mut req_ctx =
request_context().allowed_headers(Arc::new(RwLock::new(TEST_HEADERS.clone())));

req_ctx.server.vars = TEST_VARS.clone();
let eval_ctx = EvalContext::new(&req_ctx, &MockGraphqlContext);
Expand Down
4 changes: 2 additions & 2 deletions benches/request_template_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl PathString for Context {
}
}
impl HasHeaders for Context {
fn headers(&self) -> &HeaderMap {
&self.headers
fn headers(&self) -> HeaderMap {
self.headers.to_owned()
}
}
pub fn benchmark_to_request(c: &mut Criterion) {
Expand Down
4 changes: 1 addition & 3 deletions examples/jsonplaceholder.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
schema
@server(port: 8000)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 100}) {
schema @server(port: 8000) @upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42) {
query: Query
}

Expand Down
54 changes: 26 additions & 28 deletions generated/.tailcallrc.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ directive @call(
of the previous step is passed as input to the next step.
"""
steps: [Step]
) on FIELD_DEFINITION | OBJECT
) on FIELD_DEFINITION

"""
The `@expr` operators allows you to specify an expression that can evaluate to a
Expand All @@ -55,6 +55,7 @@ The @graphQL operator allows to specify GraphQL API server request to fetch data
from.
"""
directive @graphQL(
allowed_headers: [String!]
"""
Named arguments for the requested field. More info [here](https://tailcall.run/docs/guides/operators/#args)
"""
Expand All @@ -64,12 +65,7 @@ directive @graphQL(
the one specified in the `@upstream` operator.
"""
baseURL: String
"""
If the upstream GraphQL server supports request batching, you can specify the 'batch'
argument to batch several requests into a single batch request.Make sure you have
also specified batch settings to the `@upstream` and to the `@graphQL` operator.
"""
batch: Boolean!
batch: Batch
"""
The headers parameter allows you to customize the headers of the GraphQL request
made by the `@graphQL` operator. It is used by specifying a key-value map of header
Expand All @@ -82,7 +78,8 @@ directive @graphQL(
field, Tailcall requests data from the corresponding upstream field.
"""
name: String!
) on FIELD_DEFINITION | OBJECT
query: [URLQuery]
) on FIELD_DEFINITION

"""
The @grpc operator indicates that a field or node is backed by a gRPC API.For instance,
Expand All @@ -94,11 +91,13 @@ In this scenario, the GraphQL server will make a gRPC request to the gRPC endpoi
specified when the `users` field is queried.
"""
directive @grpc(
allowedHeaders: [String!]
"""
This refers to the base URL of the API. If not specified, the default base URL is
the one specified in the `@upstream` operator.
"""
baseURL: String
batch: Batch
"""
The `batchKey` dictates the path Tailcall will follow to group the returned items
from the batch request. For more details please refer out [n + 1 guide](https://tailcall.run/docs/guides/n+1#solving-using-batching).
Expand All @@ -120,7 +119,8 @@ directive @grpc(
This refers to the gRPC method you're going to call. For instance `GetAllNews`.
"""
method: String!
) on FIELD_DEFINITION | OBJECT
onRequest: String
) on FIELD_DEFINITION

"""
The @http operator indicates that a field or node is backed by a REST API.For instance,
Expand All @@ -131,11 +131,13 @@ server will make a GET request to the API endpoint specified when the `users` fi
is queried.
"""
directive @http(
allowedHeaders: [String!]
"""
This refers to the base URL of the API. If not specified, the default base URL is
the one specified in the `@upstream` operator.
"""
baseURL: String
batch: Batch
"""
The `batchKey` dictates the path Tailcall will follow to group the returned items
from the batch request. For more details please refer out [n + 1 guide](https://tailcall.run/docs/guides/n+1#solving-using-batching).
Expand Down Expand Up @@ -190,7 +192,7 @@ directive @http(
is automatically selected as the batching parameter.
"""
query: [URLQuery]
) on FIELD_DEFINITION | OBJECT
) on FIELD_DEFINITION

directive @js(
name: String!
Expand Down Expand Up @@ -365,12 +367,6 @@ directive @upstream(
"""
baseURL: String
"""
An object that specifies the batch settings, including `maxSize` (the maximum size
of the batch), `delay` (the delay in milliseconds between each batch), and `headers`
(an array of HTTP headers to be included in the batch).
"""
batch: Batch
"""
The time in seconds that the connection will wait for a response before timing out.
"""
connectTimeout: Int
Expand Down Expand Up @@ -538,6 +534,12 @@ input Step {
query: String
}

input Batch {
delay: Int!
headers: [String!]
maxSize: Int
}

input KeyValue {
key: String!
value: String!
Expand Down Expand Up @@ -709,12 +711,6 @@ input TelemetryExporter {
apollo: Apollo
}

input Batch {
delay: Int!
headers: [String!]
maxSize: Int
}

input Proxy {
url: String!
}
Expand All @@ -724,6 +720,7 @@ The @graphQL operator allows to specify GraphQL API server request to fetch data
from.
"""
input GraphQL {
allowed_headers: [String!]
"""
Named arguments for the requested field. More info [here](https://tailcall.run/docs/guides/operators/#args)
"""
Expand All @@ -733,12 +730,7 @@ input GraphQL {
the one specified in the `@upstream` operator.
"""
baseURL: String
"""
If the upstream GraphQL server supports request batching, you can specify the 'batch'
argument to batch several requests into a single batch request.Make sure you have
also specified batch settings to the `@upstream` and to the `@graphQL` operator.
"""
batch: Boolean!
batch: Batch
"""
The headers parameter allows you to customize the headers of the GraphQL request
made by the `@graphQL` operator. It is used by specifying a key-value map of header
Expand All @@ -751,6 +743,7 @@ input GraphQL {
field, Tailcall requests data from the corresponding upstream field.
"""
name: String!
query: [URLQuery]
}

"""
Expand All @@ -763,11 +756,13 @@ In this scenario, the GraphQL server will make a gRPC request to the gRPC endpoi
specified when the `users` field is queried.
"""
input Grpc {
allowedHeaders: [String!]
"""
This refers to the base URL of the API. If not specified, the default base URL is
the one specified in the `@upstream` operator.
"""
baseURL: String
batch: Batch
"""
The `batchKey` dictates the path Tailcall will follow to group the returned items
from the batch request. For more details please refer out [n + 1 guide](https://tailcall.run/docs/guides/n+1#solving-using-batching).
Expand All @@ -789,6 +784,7 @@ input Grpc {
This refers to the gRPC method you're going to call. For instance `GetAllNews`.
"""
method: String!
onRequest: String
}

"""
Expand All @@ -800,11 +796,13 @@ server will make a GET request to the API endpoint specified when the `users` fi
is queried.
"""
input Http {
allowedHeaders: [String!]
"""
This refers to the base URL of the API. If not specified, the default base URL is
the one specified in the `@upstream` operator.
"""
baseURL: String
batch: Batch
"""
The `batchKey` dictates the path Tailcall will follow to group the returned items
from the batch request. For more details please refer out [n + 1 guide](https://tailcall.run/docs/guides/n+1#solving-using-batching).
Expand Down
77 changes: 61 additions & 16 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,14 @@
"GraphQL": {
"description": "The @graphQL operator allows to specify GraphQL API server request to fetch data from.",
"type": "object",
"required": [
"name"
],
"properties": {
"allowed_headers": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
},
"args": {
"description": "Named arguments for the requested field. More info [here](https://tailcall.run/docs/guides/operators/#args)",
"type": [
Expand All @@ -538,8 +542,14 @@
]
},
"batch": {
"description": "If the upstream GraphQL server supports request batching, you can specify the 'batch' argument to batch several requests into a single batch request.\n\nMake sure you have also specified batch settings to the `@upstream` and to the `@graphQL` operator.",
"type": "boolean"
"anyOf": [
{
"$ref": "#/definitions/Batch"
},
{
"type": "null"
}
]
},
"headers": {
"description": "The headers parameter allows you to customize the headers of the GraphQL request made by the `@graphQL` operator. It is used by specifying a key-value map of header names and their values.",
Expand All @@ -551,6 +561,12 @@
"name": {
"description": "Specifies the root field on the upstream to request data from. This maps a field in your schema to a field in the upstream schema. When a query is received for this field, Tailcall requests data from the corresponding upstream field.",
"type": "string"
},
"query": {
"type": "array",
"items": {
"$ref": "#/definitions/URLQuery"
}
}
},
"additionalProperties": false
Expand All @@ -562,13 +578,30 @@
"method"
],
"properties": {
"allowedHeaders": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
},
"baseURL": {
"description": "This refers to the base URL of the API. If not specified, the default base URL is the one specified in the `@upstream` operator.",
"type": [
"string",
"null"
]
},
"batch": {
"anyOf": [
{
"$ref": "#/definitions/Batch"
},
{
"type": "null"
}
]
},
"batchKey": {
"description": "The `batchKey` dictates the path Tailcall will follow to group the returned items from the batch request. For more details please refer out [n + 1 guide](https://tailcall.run/docs/guides/n+1#solving-using-batching).",
"type": "array",
Expand All @@ -589,6 +622,12 @@
"method": {
"description": "This refers to the gRPC method you're going to call. For instance `GetAllNews`.",
"type": "string"
},
"onRequest": {
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -648,13 +687,30 @@
"path"
],
"properties": {
"allowedHeaders": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
},
"baseURL": {
"description": "This refers to the base URL of the API. If not specified, the default base URL is the one specified in the `@upstream` operator.",
"type": [
"string",
"null"
]
},
"batch": {
"anyOf": [
{
"$ref": "#/definitions/Batch"
},
{
"type": "null"
}
]
},
"batchKey": {
"description": "The `batchKey` dictates the path Tailcall will follow to group the returned items from the batch request. For more details please refer out [n + 1 guide](https://tailcall.run/docs/guides/n+1#solving-using-batching).",
"type": "array",
Expand Down Expand Up @@ -1540,17 +1596,6 @@
"null"
]
},
"batch": {
"description": "An object that specifies the batch settings, including `maxSize` (the maximum size of the batch), `delay` (the delay in milliseconds between each batch), and `headers` (an array of HTTP headers to be included in the batch).",
"anyOf": [
{
"$ref": "#/definitions/Batch"
},
{
"type": "null"
}
]
},
"connectTimeout": {
"description": "The time in seconds that the connection will wait for a response before timing out.",
"type": [
Expand Down
Loading
Loading