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

feature: Custom Extensions #2613

Closed
tusharmath opened this issue Aug 4, 2024 · 2 comments
Closed

feature: Custom Extensions #2613

tusharmath opened this issue Aug 4, 2024 · 2 comments
Assignees
Labels
state: inactive No current action needed/possible; issue fixed, out of scope, or superseded.

Comments

@tusharmath
Copy link
Contributor

This feature should allows developers to write custom Rust functions to extend Tailcall's ability.
Here is how the user experience going to look like:

Example

Let's say we want to implement langugage translation in Tailcall.

The extension is loaded using the link operator

schema
  # Dynamically Link an Extension
  @link(src: "./translate", type: Extension)
  @upstream(baseURL: "https://jsonplaceholder.typicode.com") {
  query: Query
}

type Query {
  users: [User] @http(path: "/users")
  user(id: String): [User]
    @http(path: "/users")
    # User can use the @extension directive
    @extension(name: "some_other_extension", params: ["{{.args.id}}"])
}

type User {
  id: ID
  name: String
    @extension(
      name: "translate"
      params: ["userName", "{{.value.catchPhrase}}"]
    )
  username: String
  company: Company
}

type Company {
  name: String
  catchPhrase: String
    @extension(
      name: "translate"
      params: ["catchPharse", "{{.value.catchPhrase}}"]
    )
  bs: String
}

Directive Definition
Should be added automatically to the .tailcallrc.graphql

directive @extension(name: String!, params: [String!]!) on FIELD

Rust Code

The extension needs to implement the following trait:

trait Extension {
    // Initializes the extension
    async fn init(&self);

    // Called before the IR is going to be executed
    fn prepare<Json: JsonLikeOwned>(&self, ir: IR, params: &[Json]) -> IR;

    // Called after a value is produced
    fn process<Json: JsonLikeOwned>(&self, params: &[Json], value: Json) -> Json;
}

The trait is exposed via tailcall::extensions module that published as a crate. The extension that implements the trait Extension should loaded dynamically into Tailcall.

Technical Requirements

  • Add tests and documentation wherever possible
  • Use lib loading should be async and failures should be nicely displayed to the user
@tailcallhq tailcallhq deleted a comment from algora-pbc bot Aug 5, 2024
@tailcallhq tailcallhq deleted a comment from ssddOnTop Aug 5, 2024
@karatakis karatakis self-assigned this Aug 5, 2024
Copy link

github-actions bot commented Sep 4, 2024

Action required: Issue inactive for 30 days.
Status update or closure in 7 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Sep 4, 2024
Copy link

Issue closed after 7 days of inactivity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: inactive No current action needed/possible; issue fixed, out of scope, or superseded.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants