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

Extension callbacks refactoring and middleware implementation #1939

Closed
wants to merge 12 commits into from

Conversation

k9ert
Copy link
Collaborator

@k9ert k9ert commented Oct 24, 2022

The current implementation of callbacks has a major flaw: The callback can collect results from different extensions but it can't let extensions modify the results of former extension-modifications.

So this PR does those things:

  • Refactoring of the ServiceManager to an ExtensionManager including references from services to extensions
  • Redefining the callbacks in callback.py to enable different return_styles. The string representations has been modified to be using classes
  • Implementing a new return_style called "middleware" and the old-style will be called dict:
    • dict will return a dict where the extension_id will be used as key and the returnvalue as a value (to be renamed to "collect")
    • middleware will assume that something will be passed to the callback as value and the returnvalue (might be the same or different) will be passed to the next callback of the next extension until the last extension's returnvalue will be returned by the execute_ext_callback-method.
  • The extensions might need order for that. So now every extension can specify a depends Attribute with a list of Extension-classes. The callbacks will get called so that the dependency tree and the sort-priority is respected.
  • Also we're implementing here a way for extensions to create their own callback-classes.
    image

On top of those changes, a new graphql-extension has been created:

  • Will expose a /graphql endpoint
  • Creates a new callback of type middleware which starts as an empty array and the extensions can add fields to it.
  • As an example, the devhelp extension adds a field called "bookmarks" and you can do a query (on /graphql) like:
{
  bookmarks {
    title
    desc    
    
  }
}
  • Additionally, the extension is suppose to expose core-types. As an example, the users are exposed. Query like:
{
  users {
    username
    
  }
}

@netlify
Copy link

netlify bot commented Oct 24, 2022

Deploy Preview for specter-desktop-docs canceled.

Name Link
🔨 Latest commit 6640152
🔍 Latest deploy log https://app.netlify.com/sites/specter-desktop-docs/deploys/63d8d8c1db57b5000932d61c

@relativisticelectron
Copy link
Collaborator

When you refactor the locations of the services, can you also solve #1935 ?

@k9ert k9ert force-pushed the extension_callbacks branch from 893a626 to f9cd800 Compare October 26, 2022 13:06
@k9ert
Copy link
Collaborator Author

k9ert commented Jan 31, 2023

This has been closed and instead we have now #2105 and #2106

@k9ert k9ert closed this Jan 31, 2023
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