Am 12.07.17 um 19:14 schrieb Staś Małolepszy:
I'd like to work on exposing Pontoon data via an API. The main driver
is the use case from bug 1302053:
- Stats for a locale: supported projects, status of each project.
- Stats for a project: supported locales, incomplete locales,
complete locales.
I researched using REST and GraphQL and wrote down my notes on the wiki:
https://wiki.mozilla.org/L10n:Pontoon/API
I'm still hesitating between REST and GraphQL (without Relay). The
former is familiar and well-established. The latter offers really nice
syntax and an amazing API explorer with built-in documentation. OTOH,
in case of some requests, using GraphQL naïvely may result in a lot of
queries being made to the DB.
In an effort to see if the problem of too many queries can be remedied
I implemented four simple entry points for Pontoon: projects, project,
locales and locale. Prefetch_selected optimizations are only added if
the query requires them. Cyclic queries are also explicitly forbidden
to prevent querying for projects of locales of projects etc. (I'm sure
the code I wrote for this can be generalized and made more robust, but
it's good enough for the purposes of the demo.)
https://github.com/mozilla/pontoon/compare/master...stasm:graphql
The demo is read-only . The GUI editor is only available in DEV mode.
On production, the /graphql endpoint is available without
authentication, CSP nor CSRF.
This exercise nicely shows off the good things about GraphQL, too.
See the following 1.5-minute-long silent screencast of the GraphiQL
tools which makes writing queries and debugging them a pleasure:
https://drive.google.com/file/d/0B4XpFaGRPsjHai1nUXJRdWMya3c/view?usp=sharing
I'd love to open this up for discussion. Let me know if my notes
reflect your experience working with REST and GraphQL. What other
factors and considerations are important here? What would your
preferred way forward be?
Thanks,
Staś
I also want to find some time to play with your branch. In general, but
also in the light of "can I get suggestions that are older than a week"
or something like that.
I also think that traditional REST as an impl of CRUD isn't going to
work for most of what we do. Things just scale too badly.
Which leaves us with inventing a query language, or use GraphQL. Using
something with a spec is nice. :-)
Which lead me to investigate a bit on what the libraries look like in
python land. I ended up on
https://github.com/graphql-python/graphql-core, which implements quite a
bit. Not sure which functionality graphene has precisely in the stack
yet. What concerns me a bit is the following form the README:
> This library is a port of graphql-js to Python and currently is
> up-to-date with release 0.6.0.
Which is 18 releases in the past, and well over a year.
Which leads me to the question if the python stack is actually something
we should bet on?
Axel
_______________________________________________
tools-l10n mailing list
[email protected]
https://lists.mozilla.org/listinfo/tools-l10n