flod pointed out a number of troubles he ran into when testing my branch.
Here's the summary of the fixes:
I added Project.slug and also changed the arguments to the project(slug) and
locale(code) queries.
For getting a JSON response something like this should work:
curl -X POST -d 'query={ project(slug: "amo") { name } }'
http://localhost:8000/graphql
I removed pagination for now to make it easier to support the main
goal of this API experiment which is programmatically getting data out
of Pontoon. If we need pagination in the future we can add new fields
like project_pages and locale_pages.
Pagination helps prevent getting flooded with data from the API. I
guess that's useful when building UIs, but not very useful when doing
data mining. It also helps prevent DOS attacks but I already
mitigated that to a large extent by doing introspection on the query
and forbidding cyclic relations.
I renamed Project.locales to Locale.localizations and
Locale.projects to Locale.localizations to make it clearer that those are the
"ProjectLocale" objects in Pontoon's DB.
I also added missingStrings where possible. missingStrings are not stored in
the DB, so I had to add them explicitly by computing them:
https://github.com/stasm/pontoon/commit/f16c1eeb94b65d9f9fff1c112bf6f424983fd5d2
The query structure was rather verbose with a lot of intermediate "items"
objects. The goal of those was to make it possible to provide meta-information
about the results, like the total count of items (which isn't an item on its
own). I removed "items" for now and flattened the query structure. The main
use-case for now is the data itself rather than the counts.
We could also establish a convention in the future that for any Foo, "foos" is
a simple list of Foos and foo_pages is a paginated result with meta-information.
To illustrate the changes, here are a few example queries that you can try
running on my branch:
query sumo {
project(slug: "sumo") {
missingStrings,
localizations {
locale {
name
}
missingStrings
}
}
}
query french {
locale(code: "fr") {
missingStrings,
localizations {
project {
name
}
missingStrings
}
}
}
query amo {
project(slug: "amo") {
name
}
}
query allProjects {
projects {
name
localizations {
locale {
name
}
}
}
}
Also interesting to note is that last night a big PR was merged to graphene and
it looks like version 2.0 is in the works:
https://github.com/graphql-python/graphene/pull/500
This might answer some of our worries about graphene not being maintained. And
introduce new ones about it being not stable enough :)
Staś
_______________________________________________
tools-l10n mailing list
[email protected]
https://lists.mozilla.org/listinfo/tools-l10n