mozilla / tofino

Project Tofino is a browser interaction experiment.
https://mozilla.github.io/tofino
Apache License 2.0
647 stars 68 forks source link

Make Tofino use generic /query and /transact endpoints #1575

Open ncalexan opened 7 years ago

ncalexan commented 7 years ago

Right now, Tofino uses special endpoints provided by the Datomish User Agent Service. (These are endpoints like /stars or /visits; see the documentation at https://github.com/mozilla/datomish-user-agent-service/blob/master/docs/api.md.) However, we'd like to push much of this work into the client, the intention being to allow the client to experiment and move faster than the UAS can. (I see this as being the interesting workflow innovation of the GraphQL movement.)

For Tofino, that means using the generic /query and /transact endpoints and managing the Datomish schema in the client. The generic endpoints exist (see https://github.com/mozilla/datomish-user-agent-service/blob/master/src/datomish_user_agent_service/server.cljs#L94 and https://github.com/mozilla/datomish-user-agent-service/blob/master/src/datomish_user_agent_service/server.cljs#L125) but are undocumented. (They also have some bugs, although I can't see one filed for this: namespaced keywords are converted to JS incorrectly.)

This ticket tracks replacing the Tofino HTTP requests to the special endpoints around https://github.com/mozilla/tofino/blob/master/app/shared/user-agent-http-client.js#L88 with requests to the generic endpoints. The relevant transactions and query strings can be lifted out of the Datomish User Agent Service whole-cloth from https://github.com/mozilla/datomish-user-agent-service/blob/master/src/datomish_user_agent_service/api.cljc. Note that these definitions are written in Clojure, so there's some translation into strings built with JS needed.

There will also need to be a new HTTP POST to /transact right when Tofino starts up in order to ensure the Tofino browser schema is installed. That schema can be lifted from around https://github.com/mozilla/datomish-user-agent-service/blob/master/src/datomish_user_agent_service/api.cljc#L138 (again with some light rewriting into strings).

As it stands, this will completely break the Web Socket interface, because the WS messages are only sent to clients when the server handles the special endpoints. (See, for example, https://github.com/mozilla/datomish-user-agent-service/blob/master/src/datomish_user_agent_service/server.cljs#L168.) To really address this, we'd need to make the User Agent Service allow clients to register generic transaction listeners, which isn't yet done. It's tracked by https://github.com/mozilla/datomish-user-agent-service/issues/17, which isn't trivial to do. I think, for now, we could profitably make a start on this ticket and leave the WS interface for later.

Finally, you'll know everything is working when Tofino works and there are no HTTP requests other than to /query and /transact. At that point we can remove the special endpoints from the UAS entirely, and the client (Tofino!) will really own the browser DB code \o/

ncalexan commented 7 years ago

It's not 100% clear to me that we want to do this. We could, instead, implement the UAS in Rust, backed by Mentat-in-Rust. My instinct is that this generic approach is better, and will let us innovate in clients faster, but you might have a different opinion. Do comment!

ncalexan commented 7 years ago

@victorporof we talked about this in today's meeting; hope this explains what I meant. Ask questions!