-
Notifications
You must be signed in to change notification settings - Fork 52
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
Plugin should have module-wise resolvers similar to the wasm #603
Comments
Looks good! Anything we can do to bring the experience closer to the wasm one is a good thing in my view |
Yes I agree @Niraj-Kamdar, this is very well thought out. I agree with moving in this direction ASAP so we can properly support environments within plugins 👏 |
Here's the design spec for improving plugin development experience: Plugin Directory structureHere's the how a project directory structure for a plugin would look like:
What users need to write?Plugin Manifestmanifest file would become similar to the wasm manifest file
Here entrypoint will be root directory where all the code is situated and must contain an Interface schemaUser should write interface for any plugins they build, this is to ensure that any implementation of a plugin interface would share the same interface regardless of system, languages and environments and could be used in wasm polywrapper in similar ways. type Query {
getData(): String!
getDataByArg1(arg1: String!): String!
} Side-discussion on how would it affect polywrap devs who are going to use these pluginsIn client, users can use interface and implementation URI configs to attach one or more implementation plugins for an interface, It will be the reponsibility of wrapper developer to go over these implementations using the The reason for not automating execution of interface implementations are: In some cases like logger, we may want to execute all the implementations for streaming logs to different services: Console, Filesystem, Http, etc while in cases like cache store you may want to first check in-memory cache then file-system and lastly network caches like memcache, this is completely different flow then executing all the implementations and we have no way of knowing how developer of polywrap would like it to be implemented so it'd be better to just leave this upto devs to implement it however they wants. Here's the client side code snippet to attach interface with an implementation const client = await getClient({
plugins: [...]
interfaces: [
{
interface: interfaceUri,
implementations: [implementationUri],
}
],
}); Here, implementation can either plugin or other polywrapper. Once attaching implemntations with interfaces user can query polywrapper normally. Here's the possible wrapper side code snippet
Module schema -> (path:
|
Currently, when we create a plugin, we will just create a single schema file, a Plugin class and resolvers for both query and mutation module. This will create issues while porting some features from wasm polywrapper to plugin that are module dependent Ex: env
In wasm polywrapper, we can import
env
directly from thew3
and use it since the both query and mutation modules will always be decoupled in the separate files and we can correctly have env of eitherQueryEnv
orMutationEnv
type depending on the module but in case ofplugin
, since both modules are in same file and we only generate one singlew3
, we can haveenv
with both theQueryEnv
andMutationEnv
types so we can't assign it either one of the type, though we can workaround this by creating 2 separate variables:queryEnv
,mutationEnv
but that wouldn't be a good and consistent experience. Not to mention in the future we may have more than 2 modules.So a better solution would be to create separate directories for every module with its own w3 generated codes in plugin just like we have it in wasm polywrappers.
Ex: In plugin we can have classes for all the available modules:
This will replace current resolvers with module wise classes, we can pass state in constructor from the Plugin class, this state can even be shared or isolated depending on how plugin devs want it to be implemented.
Ex: Plugin class would just be implementation of the core Plugin interface without any other methods.
We may not even need configs for most of the cases after env support since we can pass it using env from the client, although we would still need it in some cases where user wants to pass an object instance instead of string serializable env so for that having it is still necessary.
The text was updated successfully, but these errors were encountered: