tailcall
tailcall copied to clipboard
feat: ability to configure request handler
Current We can only setup one request handler in a JS worker file. This proposal intends to break that restriction
Proposal
type schema @upstream(onRequest: "onRequest") {
# ...
}
type Query {
foo: Foo @http(path: "/foo", onRequest: "onRequestFoo")
bar: Bar @http(path: "/bar", onRequest: "onRequestBar")
baz: Bar @http(path: "/baz")
}
function onRequest (request) {
//
}
function onRequestFoo (request) {
//
}
function onRequestBar (request) {
//
}
In the above implementation when:
- We query
foo,onRequestFoois called with the request params. - We query
bar,onRequestBaris called with the request params. - We query
baz,onRequest(default handler) is called with the request params.
/bounty 250
💎 $250 bounty • Tailcall Inc.
Steps to solve:
- Start working: Comment
/attempt #1271with your implementation plan - Submit work: Create a pull request including
/claim #1271in the PR body to claim the bounty - Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts
Additional opportunities:
- 🔴 Livestream on Algora TV while solving this bounty & earn $200 upon merge! Comment
/livestreamonce live
🙏 Thank you for contributing to tailcallhq/tailcall! 🧐 Checkout our guidelines before you get started.
| Attempt | Started (GMT+0) | Solution |
|---|---|---|
| 🔴 @Bhavyajain21 | Mar 2, 2024, 9:00:13 AM | WIP |
| 🟢 @webbdays | Mar 17, 2024, 3:51:28 PM | WIP |
| 🔴 @Rutik7066 | Apr 18, 2024, 5:31:33 AM | WIP |
| 🟡 @varshith257 | May 15, 2024, 7:48:16 PM | WIP |
@Bhavyajain21: The Tailcall Inc. team prefers to assign a single contributor to the issue rather than let anyone attempt it right away. We recommend waiting for a confirmation from a member before getting started.
@tusharmath why not add a new file instead of new functions on the single file? For large applications, it'd make it more maintainable for the users, and it follows the idea of SRP (as serverless for example, that you have one single entry point to each file implementation). What do you think?
Just as suggestions, but anyways, I'll try to implement as it is. /attempt #1271
@ologbonowiwi We could build that into tailcall. But I would leave that up to the developer to figure out how they would like to bundle their js file. They write code in smaller files but ultimately need to expose one file that can be imported and executed.
@tusharmath I think the user can have a logic like this in js worker. pseudo code :
// onRequest being a generic handler/interceptor.
function onRequest ({request}) {
// some logic to get path
......
// switch case for path
switch(request_path) {
case "/foo":
return onRequestFoo(request);
break;
case "/bar":
return onRequestBar(request);
break;
default:
// do nothing for others like Baz, just return request back to caller.
return {request} ;
}
}
function onRequestFoo ({request}) {
//
}
function onRequestBar ({request}) {
//
}
This is very easy to user. Making onrequest a generic handler/interceptor. No changes required in rust code.
What is the advantage the user gets if supposed to configure it in .graphql format?
Thanks.
@tusharmath is this still in plan?
Yes.
@tusharmath all the http requests will go through the on_request method of RequestFilter struct right? Please confirm.
Yes. The global one defined in upstream. This is happening right now also.
Hi @tusharmath, I made it work by passing the onRequest as a header in the request to reach the on_request func in RequestFilter. Once it reach the on_request func, i remove those headers and collect values so that we can use them there. we should make sure we pass as headers and remove them before actual request is made. we should handle like pass as headers only when js worker file is linked so that we can remove them in on_request func and use there. which we can handle. is this approach ok? Thank you.
Hi @tusharmath, Please comment on this. Thank you.
Hi @tusharmath, I have done with requested changes. Please review. Thank you.
/attempt #1271
| Algora profile | Completed bounties | Tech | Active attempts | Options |
|---|---|---|---|---|
| @Rutik7066 | 1 tailcallhq bounty + 4 bounties from 3 projects |
Go, Rust, TypeScript & more |
Cancel attempt |
[!NOTE] The user @webbdays is already attempting to complete issue #1271 and claim the bounty. We recommend checking in on @webbdays's progress, and potentially collaborating, before starting a new solution.
Hi @Rutik7066, its done. merging is blocked due to #1570 try #1570
@Rutik7066: Reminder that in 1 days the bounty will become up for grabs, so please submit a pull request before then 🙏
/attempt #1271
I will take up on this important feature to be implemented as quickly as possible.
| Algora profile | Completed bounties | Tech | Active attempts | Options |
|---|---|---|---|---|
| @varshith257 | 1 tailcallhq bounty | TypeScript, Go |
Cancel attempt |
[!NOTE] The user @webbdays is already attempting to complete issue #1271 and claim the bounty. We recommend checking in on @webbdays's progress, and potentially collaborating, before starting a new solution.
@varshith257: Reminder that in 1 days the bounty will become up for grabs, so please submit a pull request before then 🙏
💡 @webbdays submitted a pull request that claims the bounty. You can visit your bounty board to reward.
Hi @tusharmath, Please process this bounty. Still in pending.
@tusharmath algora sent bounty now. I have got 2 now. tip and this one PLease look into it.