Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

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

Open
ncalexan opened this issue Feb 8, 2017 · 2 comments
Open

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

ncalexan opened this issue Feb 8, 2017 · 2 comments

Comments

@ncalexan
Copy link
Member

ncalexan commented Feb 8, 2017

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 mozilla/datomish-user-agent-service#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
Copy link
Member Author

ncalexan commented Feb 8, 2017

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
Copy link
Member Author

ncalexan commented Feb 8, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant