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

feat: create @call operator #881

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
3a35b99
feat(call operator): add basic types
ologbonowiwi Jan 3, 2024
56b731e
feat: implement most of call operator
ologbonowiwi Jan 3, 2024
b2c54a3
chore(jsonplaceholder): use `@call` directive
ologbonowiwi Jan 3, 2024
9ed145e
feat(call): override http path args
ologbonowiwi Jan 3, 2024
6eca588
test(call): add test for query operation
ologbonowiwi Jan 3, 2024
3e6f6f7
test(call): add test cases for errors
ologbonowiwi Jan 3, 2024
9df332b
test(call): add test for lack of operator
ologbonowiwi Jan 3, 2024
14fb878
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 3, 2024
397e06a
refactor(call): remove mutation for lack of use case
ologbonowiwi Jan 3, 2024
0e5bed6
fix: fail on lack of http resolver
ologbonowiwi Jan 3, 2024
e46de03
test: add test for invalid resolver
ologbonowiwi Jan 3, 2024
63a3d52
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 3, 2024
debceee
docs(tailcallrc): add `@call` operator directive
ologbonowiwi Jan 3, 2024
000af1c
refactor(call): use `Valid::from_option` instead of `if let Some`
ologbonowiwi Jan 3, 2024
b0d82b0
refactor(call): remove useless format
ologbonowiwi Jan 3, 2024
52dc898
fix(tailcallrc): add `on FIELD_DEFINITION` for `@call` directive
ologbonowiwi Jan 3, 2024
e27963e
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 3, 2024
1a0c949
Merge branch 'main' into feat/#846/create-call-operator
ologbonowiwi Jan 3, 2024
0488069
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 3, 2024
152d051
feat(call operator): add basic types
ologbonowiwi Jan 3, 2024
6b78f78
feat: implement most of call operator
ologbonowiwi Jan 3, 2024
0607dd5
chore(jsonplaceholder): use `@call` directive
ologbonowiwi Jan 3, 2024
8ca2ba5
feat(call): override http path args
ologbonowiwi Jan 3, 2024
1303d09
test(call): add test for query operation
ologbonowiwi Jan 3, 2024
8a7daaf
test(call): add test cases for errors
ologbonowiwi Jan 3, 2024
13df7cf
test(call): add test for lack of operator
ologbonowiwi Jan 3, 2024
aa69879
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 3, 2024
28420f5
refactor(call): remove mutation for lack of use case
ologbonowiwi Jan 3, 2024
feb6ba1
fix: fail on lack of http resolver
ologbonowiwi Jan 3, 2024
f81a972
test: add test for invalid resolver
ologbonowiwi Jan 3, 2024
9b591a9
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 3, 2024
1fb8a8e
docs(tailcallrc): add `@call` operator directive
ologbonowiwi Jan 3, 2024
6305bd6
refactor(call): use `Valid::from_option` instead of `if let Some`
ologbonowiwi Jan 3, 2024
f8adc1e
refactor(call): remove useless format
ologbonowiwi Jan 3, 2024
40467b5
fix(tailcallrc): add `on FIELD_DEFINITION` for `@call` directive
ologbonowiwi Jan 3, 2024
380d805
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 3, 2024
fba92c1
docs(call): add WIP call docs
ologbonowiwi Jan 6, 2024
a167b49
refactor: update `call.args` into `HashMap<String, String>`
ologbonowiwi Jan 8, 2024
9aa1edc
Merge branch 'feat/#846/create-call-operator' of github.com:ologbonow…
ologbonowiwi Jan 8, 2024
98fed0e
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 8, 2024
930a378
Merge branch 'main' into feat/#846/create-call-operator
ologbonowiwi Jan 8, 2024
112b34f
Merge branch 'feat/#846/create-call-operator' of github.com:ologbonow…
ologbonowiwi Jan 8, 2024
c9cec87
Merge branch 'main' into feat/#846/create-call-operator
amitksingh1490 Jan 11, 2024
92789eb
Merge branch 'main' into feat/#846/create-call-operator
amitksingh1490 Jan 11, 2024
143b456
Merge branch 'feat/#846/create-call-operator' of github.com:ologbonow…
ologbonowiwi Jan 11, 2024
c9c53f9
test: add tests to `@graphQL` resolver on call operator
ologbonowiwi Jan 11, 2024
f6e2d52
feat: implement graphql operator
ologbonowiwi Jan 11, 2024
ecb469b
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 11, 2024
b1df2ea
Merge branch 'main' into feat/#846/create-call-operator
ologbonowiwi Jan 11, 2024
0042b5c
Merge branch 'main' into feat/#846/create-call-operator
ologbonowiwi Jan 12, 2024
39ac595
Merge branch 'feat/#846/create-call-operator' of github.com:ologbonow…
ologbonowiwi Jan 14, 2024
8b4e5e2
test: add tests for argument mismatch
ologbonowiwi Jan 14, 2024
df14c21
test: include test for http operator args mismatch
ologbonowiwi Jan 15, 2024
4bcff13
chore: checkpoint
ologbonowiwi Jan 16, 2024
2c4a41e
Merge branch 'main' of https://github.com/tailcallhq/tailcall into fe…
ologbonowiwi Jan 16, 2024
0e2dd40
refactor: make validate return the `b_field` itself
ologbonowiwi Jan 16, 2024
c2a72c7
refactor: move ownership to `validate_field` method
ologbonowiwi Jan 16, 2024
7817ee3
test: add mutation breaking tests
ologbonowiwi Jan 17, 2024
ac8c49e
docs: update args typings
ologbonowiwi Jan 17, 2024
41a70be
chore: uncomment simple working solution
ologbonowiwi Jan 17, 2024
305e84c
feat: fail with "no argument found" message
ologbonowiwi Jan 18, 2024
ad4730f
feat: add field name on trace
ologbonowiwi Jan 18, 2024
79e2d9d
test: add mismatch graphql args test
ologbonowiwi Jan 18, 2024
cf8af49
feat: move implementation to inside call operator and implement graph…
ologbonowiwi Jan 18, 2024
0f0cbc7
test: delete broken mutation nested tests
ologbonowiwi Jan 18, 2024
9a1d2cb
Merge branch 'main' of https://github.com/tailcallhq/tailcall into fe…
ologbonowiwi Jan 18, 2024
802abaf
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 18, 2024
9185fb7
refactor: create method to find value
ologbonowiwi Jan 18, 2024
f820d89
docs: remove broken stuff from docs
ologbonowiwi Jan 18, 2024
e77fbc6
refactor: use `!_.any()` instead of `_.find().is_none()`
ologbonowiwi Jan 18, 2024
4fa7bf3
Update examples/.tailcallrc.graphql
ologbonowiwi Jan 18, 2024
0fc8b69
test: add test case for header mismatch on graphql
ologbonowiwi Jan 18, 2024
8c8c93f
test: rename url mismatch test case name
ologbonowiwi Jan 18, 2024
3463a82
Merge branch 'feat/#846/create-call-operator' of github.com:ologbonow…
ologbonowiwi Jan 18, 2024
405d809
Merge branch 'main' of https://github.com/tailcallhq/tailcall into fe…
ologbonowiwi Jan 19, 2024
ca46089
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 19, 2024
dc9b982
docs: add docs for `Call` operator
ologbonowiwi Jan 19, 2024
cf2598c
refactor: create `compile_call` method
ologbonowiwi Jan 19, 2024
2741014
feat: add call on `expr`
ologbonowiwi Jan 19, 2024
ac956f4
feat: add call on resolvable directives
ologbonowiwi Jan 19, 2024
d14550f
refactor: change `req_template` without `mut`
ologbonowiwi Jan 21, 2024
792a592
checkpoint query support
ologbonowiwi Jan 22, 2024
f4d8c41
feat: support mock based on headers
ologbonowiwi Jan 24, 2024
d732830
test(`@graphQL`): create tests for call resolver
ologbonowiwi Jan 24, 2024
f8c45f7
feat: implement `@call` for `graphql.headers`
ologbonowiwi Jan 24, 2024
623d6fa
test(`@http`): create tests mocking headers value
ologbonowiwi Jan 24, 2024
338f748
feat(`@call`): fill `http.headers` with `args`
ologbonowiwi Jan 24, 2024
5a3cf6e
test(`@http`): create tests replacing `http.query` by `call.args`
ologbonowiwi Jan 24, 2024
d1bf6c4
feat: implement `query` replacement on `http`
ologbonowiwi Jan 24, 2024
9e91877
test: uncomment `userWithPosts` test
ologbonowiwi Jan 24, 2024
c3b77d1
feat: create basic test for `@grpc` operator
ologbonowiwi Jan 24, 2024
7778948
test: add grpc arg test
ologbonowiwi Jan 24, 2024
182969d
feat: support `@grpc` on `@call`
ologbonowiwi Jan 24, 2024
16ba5f0
Merge branch 'main' of github.com:tailcallhq/tailcall into feat/#846/…
ologbonowiwi Jan 24, 2024
2481c98
refactor: delete unused file
ologbonowiwi Jan 24, 2024
b6ac5c3
style: fix needless borrow error
ologbonowiwi Jan 24, 2024
ce5b63b
style: fix `cmp-owned` rule
ologbonowiwi Jan 24, 2024
46ed159
refactor: remove unreachable code
ologbonowiwi Jan 24, 2024
8f6f5c7
Merge branch 'main' into feat/#846/create-call-operator
tusharmath Jan 27, 2024
91eddea
Merge branch 'main' into feat/#846/create-call-operator
tusharmath Jan 27, 2024
1e01e3b
Merge branch 'main' into feat/#846/create-call-operator
ologbonowiwi Jan 27, 2024
2add539
feat: add call directive on `into_document`
ologbonowiwi Jan 29, 2024
e89132d
Merge branch 'main' of github.com:tailcallhq/tailcall into feat/#846/…
ologbonowiwi Jan 29, 2024
ba23a31
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 29, 2024
7993df6
refactor: return field on `validate_field`
ologbonowiwi Jan 29, 2024
8039fbb
Merge branch 'feat/#846/create-call-operator' of github.com:ologbonow…
ologbonowiwi Jan 29, 2024
0c05f71
test: remove character breaking tests
ologbonowiwi Jan 29, 2024
a867c58
fix: delete doc for call operator
ologbonowiwi Jan 29, 2024
e26a9b3
refactor: use `try_from` to avoid unreachable code
ologbonowiwi Jan 29, 2024
4bffd93
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 29, 2024
ec7c9f4
feat: support mutation on call
ologbonowiwi Jan 29, 2024
0c56c4f
style: run `./lint.sh --mode=fix`
ologbonowiwi Jan 29, 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
2 changes: 1 addition & 1 deletion examples/jsonplaceholder.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ type Post {
userId: Int!
title: String!
body: String!
user: User @http(path: "/users/{{value.userId}}")
user: User @call(query: "user", args: [{key: "id", value: "{{value.userId}}"}])
tusharmath marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions src/blueprint/from_config/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ fn to_fields(object_name: &str, type_of: &config::Type, config: &Config) -> Vali
.and(update_const_field().trace(config::Const::trace_name().as_str()))
.and(update_graphql(&operation_type).trace(config::GraphQL::trace_name().as_str()))
.and(update_modify().trace(config::Modify::trace_name().as_str()))
.and(update_call(&operation_type).trace(config::Call::trace_name().as_str()))
.and(update_nested_resolvers())
.try_fold(&(config, field, type_of, name), FieldDefinition::default())
};
Expand Down Expand Up @@ -383,6 +384,7 @@ fn to_fields(object_name: &str, type_of: &config::Type, config: &Config) -> Vali
const_field: source_field.const_field.clone(),
graphql: source_field.graphql.clone(),
cache: source_field.cache.clone(),
call: source_field.call.clone(),
};
to_field(&add_field.name, &new_field)
.and_then(|field_definition| {
Expand Down
59 changes: 59 additions & 0 deletions src/blueprint/from_config/operators/call.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use crate::blueprint::*;
use crate::config;
use crate::config::{Config, Field, GraphQLOperationType};
use crate::directive::DirectiveCodec;
use crate::try_fold::TryFold;
use crate::valid::Valid;

pub fn update_call(
operation_type: &GraphQLOperationType,
) -> TryFold<'_, (&Config, &Field, &config::Type, &str), FieldDefinition, String> {
TryFold::<(&Config, &Field, &config::Type, &str), FieldDefinition, String>::new(
move |(config, field, type_of, name), b_field| {
let Some(call) = &field.call else {
return Valid::succeed(b_field);
};

let type_and_field = if let Some(mutation) = &call.mutation {
Valid::succeed(("Mutation", mutation.as_str()))
ologbonowiwi marked this conversation as resolved.
Show resolved Hide resolved
} else if let Some(query) = &call.query {
Valid::succeed(("Query", query.as_str()))

Check warning on line 20 in src/blueprint/from_config/operators/call.rs

View check run for this annotation

Codecov / codecov/patch

src/blueprint/from_config/operators/call.rs#L17-L20

Added lines #L17 - L20 were not covered by tests
} else {
Valid::fail("call must have one of mutation or query".to_string())

Check warning on line 22 in src/blueprint/from_config/operators/call.rs

View check run for this annotation

Codecov / codecov/patch

src/blueprint/from_config/operators/call.rs#L22

Added line #L22 was not covered by tests
};

type_and_field
.and_then(|(type_name, field_name)| {
Valid::from_option(
config.find_type(type_name),
format!("{} type not found on config", type_name),
)
.zip(Valid::succeed(field_name))
})
.and_then(|(query_type, field_name)| {
Valid::from_option(
query_type.fields.get(field_name),
format!("{} field not found", field_name),
)
.and_then(|field| {
if !field.has_resolver() {
return Valid::fail(format!("{} field has no resolver", field_name));
}

Valid::succeed(field)
})
})
.and_then(|field| {
// TO-DO: parse call.args into a way that `update_http`, `update_grpc` and `update_graphql` can use
ologbonowiwi marked this conversation as resolved.
Show resolved Hide resolved

TryFold::<(&Config, &Field, &config::Type, &str), FieldDefinition, String>::new(|_, b_field| {
Valid::succeed(b_field)
})
.and(update_http().trace(config::Http::trace_name().as_str()))
.and(update_grpc(operation_type).trace(config::Grpc::trace_name().as_str()))
.and(update_graphql(operation_type).trace(config::GraphQL::trace_name().as_str()))
.try_fold(&(config, field, type_of, name), b_field)
})

Check warning on line 56 in src/blueprint/from_config/operators/call.rs

View check run for this annotation

Codecov / codecov/patch

src/blueprint/from_config/operators/call.rs#L25-L56

Added lines #L25 - L56 were not covered by tests
},
)
}
ologbonowiwi marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/blueprint/from_config/operators/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod call;
mod const_field;
mod graphql;
mod grpc;
mod http;
mod modify;
mod unsafe_field;

pub use call::*;
pub use const_field::*;
pub use graphql::*;
pub use grpc::*;
Expand Down
11 changes: 11 additions & 0 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ pub struct Field {
#[serde(default, skip_serializing_if = "is_default")]
pub http: Option<Http>,
#[serde(default, skip_serializing_if = "is_default")]
pub call: Option<Call>,
#[serde(default, skip_serializing_if = "is_default")]
pub grpc: Option<Grpc>,
#[serde(rename = "unsafe", default, skip_serializing_if = "is_default")]
pub unsafe_operation: Option<Unsafe>,
Expand Down Expand Up @@ -387,6 +389,15 @@ pub struct Http {
pub group_by: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
pub struct Call {
#[serde(default, skip_serializing_if = "is_default")]
pub query: Option<String>,
#[serde(default, skip_serializing_if = "is_default")]
pub mutation: Option<String>,
pub args: KeyValues,
ologbonowiwi marked this conversation as resolved.
Show resolved Hide resolved
}
ologbonowiwi marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Grpc {
Expand Down
6 changes: 4 additions & 2 deletions src/config/from_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use async_graphql::parser::Positioned;
use async_graphql::Name;

use super::Cache;
use crate::config::{self, Config, GraphQL, Grpc, RootSchema, Server, Union, Upstream};
use crate::config::{self, Call, Config, GraphQL, Grpc, RootSchema, Server, Union, Upstream};
use crate::directive::DirectiveCodec;
use crate::valid::Valid;

Expand Down Expand Up @@ -222,7 +222,8 @@ where
.zip(GraphQL::from_directives(directives.iter()))
.zip(Cache::from_directives(directives.iter()))
.zip(Grpc::from_directives(directives.iter()))
.map(|(((http, graphql), cache), grpc)| {
.zip(Call::from_directives(directives.iter()))
.map(|((((http, graphql), cache), grpc), call)| {
let unsafe_operation = to_unsafe_operation(directives);
let const_field = to_const_field(directives);
config::Field {
Expand All @@ -239,6 +240,7 @@ where
const_field,
graphql,
cache: cache.or(parent_cache),
call,
}
})
}
Expand Down
Loading