askql icon indicating copy to clipboard operation
askql copied to clipboard

Introduce a mechanism for adding third-party AskVM resources

Open czerwinskilukasz1 opened this issue 5 years ago • 1 comments

Some of the resources on AskVM are built-in (like if, call or query), some of them are defined in source code running the server, but there is no good way to add third-party packages of resources without modifying the existing source code. Resources like:

  • database access
  • Facebook / GitHub / any other service API client
  • payment providers
  • etc.

What kind of solution would you suggest? Ideas from all readers are welcome :)

czerwinskilukasz1 avatar Jun 17 '20 14:06 czerwinskilukasz1

@czerwinskilukasz1 here's how you can add a third-party AskVM resource:

const askql = require("askql");
const { resource } = askql.askvm;

(async () => {
  const result = await askql.runUntyped(
    {
      resources: {
        ...askql.askvm.resources,
        env: resource({
          resolver() {
            return process.env;
          },
        }),
      },
    },
    askql.parse("ask { env:at('PATH') }")
  );

  console.log(JSON.stringify(result, null, 2));
})();

I have just tested it with the production version 1.0.2

mhagmajer avatar Jun 18 '20 13:06 mhagmajer