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

improvements for plugins implementation #74

Merged
merged 5 commits into from
Aug 20, 2023
Merged

improvements for plugins implementation #74

merged 5 commits into from
Aug 20, 2023

Conversation

YassinEldeeb
Copy link
Member

@YassinEldeeb YassinEldeeb commented Aug 18, 2023

Plugins V2:

Improves upon @dotansimha's v1 implementation based on the review given at #40

Features ✨

  • Introduce Global Plugins, which gets applied to every endpoint

    ...
    
    endpoints:
      - path: /graphql
        from: countries
    
      - path: /test
        from: countries
        plugins:
          - type: verbose_logging
          
    plugins:
      - type: json_content_type_response
  • Introduce a new hook on_upstream_graphql_response which modifies the response data before sending it to the client.

    fn on_upstream_graphql_response<'a>(&self, _response: &mut Result<hyper::Response<Body>, EndpointError>) {}
  • Introducing our first useful plugin 🥁🥁🥁 "JSON Content Type Header", it intercepts the response from any source before it being sent to the client, and attaches the content type header, so that clients like Postman can show the result in a JSON format instead of being rendered as text. and It's applied as a default plugin.

Performance Improvements 🚀

  • Zero cost empty hooks implementation, when a plugin uses 1 of the many hooks available, it currently have zero cost at runtime. Previously, it used to take ownership of the data and return it back to the variable, resulting in 2 re-initialization of the variable of the same value.
  • Resolves the issue of Mutex usage on the upstream service, now it can handle requests concurrently instead of being blocked while the other request releases the lock.
  • Upstream request data parts are now shared instead of being cloned, so the entire execution now uses shared memory, resulting in zero clones.
  • At runtime, plugins are now accessed without an Arc and RwLock, resulting in a much faster access, eliminating write locks, and storing the plugins entirely on the Stack instead of the heap with the above eliminated smart pointers.

@dotansimha dotansimha changed the title feat: plugins v2 improvements for plugins implementation Aug 20, 2023
@dotansimha dotansimha merged commit 3dba1b0 into master Aug 20, 2023
4 checks passed
@YassinEldeeb
Copy link
Member Author

lol, now I realize how “plugins v2” sounded like a breaking change when it’s totally not, idk why I named it that way 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants