0.1.0 • Published 6 years ago
microql v0.1.0
MicroQL
Sort of inspired by GraphQL. But what if you have regular old JSON REST APIs which may be yours or third parties, and you want to compose them and return some kind of result? This lets you do that, and also integrate other sync and async tasks declaratively.
I probably just reinvented lisp or something. Oh well.
query({
debug: true,
input: {creatureType: 'Monkey'},
services: {fieldAgent, truck},
jobs: {
// result service action args
monkey: ['fieldAgent', 'findAnimal', {animal: '$.input.creatureType'}],
caged: ['fieldAgent', 'tranquilize', {animal: '$.monkey'}],
pet: ['truck', 'bringHome', {animal: '$.caged'}],
},
}, (error, {pet}) => {
// yay, we have a monkey as a pet
expect(error).to.not.exist
expect(pet).to.exist
expect(pet).to.equal('Friendly Sleepy Monkey')
done()
})
See the full test here.
What just happened?
- We assume you want to aggregate results from multiple async services.
- Any async service (API, network, DB, hard disk) can be represented as a function:
(action, args, next) =>
- Describe your inputs/outputs and MicroQL will infer the dependency graph and execute in maximum concurrency.
- All results from a query will be accumulated on a single JS object root.
How's it work?
Well, it's a combination of async.auto
and jsonpath
. Async auto builds an execution graph for async tasks, but you have to describe the dependencies yourself. But if we make the assumption that you describe your inputs using jsonpath
, we can infer your dependencies for you. The result is there's no duplicated code and it feels similar to writing a SQL query.
0.1.0
6 years ago