Tpt added a comment. |
I just started to implement a simple GraphQL wrapper on top of the Wikibase API in order to see how it could be implemented in practice. It currently maps most of the PHP DataModel structures with an interface similar to the one of the JSON API and provides some demo queries and mutations.
Here are some samples (click on the execute button to retrieve the execution of the query):
- Get the English label, the French description of aliases of Q42 and its sitelink in ruwiki with the English label of its badges: https://tools.wmflabs.org/tptools/wdql.html?query=%7B%0A%20%20champollion%3A%20item(id%3A%20%22Q260%22)%20%7B%0A%20%20%20%20id%0A%20%20%20%20labels%20%7B%0A%20%20%20%20%20%20en%20%7B%0A%20%20%20%20%20%20%20%20value%0A%20%20%20%20%20%20%20%20language%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20descriptions%20%7B%0A%20%20%20%20%20%20fr%20%7B%0A%20%20%20%20%20%20%20%20value%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20aliases%20%7B%0A%20%20%20%20%20%20fr%20%7B%0A%20%20%20%20%20%20%20%20value%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20sitelinks%20%7B%0A%20%20%20%20%20%20ruwiki%20%7B%0A%20%20%20%20%20%20%20%20site%0A%20%20%20%20%20%20%20%20title%0A%20%20%20%20%20%20%20%20badges%20%7B%0A%20%20%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20%20%20labels%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20en%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A
- Retrieve the VIAF id of Q260 with some data about the property and references: https://tools.wmflabs.org/tptools/wdql.html?query=%7B%0A%20%20champollion%3A%20item(id%3A%20%22Q260%22)%20%7B%0A%20%20%20%20claims%20%7B%0A%20%20%20%20%20%20P214%20%7B%0A%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20rank%0A%20%20%20%20%20%20%20%20mainsnak%20%7B%0A%20%20%20%20%20%20%20%20%20%20...%20on%20PropertyValueSnak%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20property%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20datatype%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20datatype%0A%20%20%20%20%20%20%20%20%20%20%20%20value%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20type%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20...%20on%20StringValue%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20references%20%7B%0A%20%20%20%20%20%20%20%20%20%20hash%0A%20%20%20%20%20%20%20%20%20%20snaks%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20P143%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20type%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20...%20on%20PropertyValueSnak%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20...%20on%20Entity%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A
- An example of mutation (set the English label of Q42):
mutation foo { foo: setLabel(id: "Q42", language: "en", value: "Douglas Adams") }
Warning: there is no way to log-in yet so if you try to execute it is going to fail because labs IPs are blocked.
Implementation related points:
- Source code is here: https://phabricator.wikimedia.org/source/tool-tptools/browse/master/ the interesting files are public_html/wdql.php (entry point) and src/GraphQL/*
- I am using a GraphQL PHP library https://webonyx.github.io/graphql-php/ that is fairly stable and provides advanced features like query complexity limitations. If we want in the far future provide a GraphQL API in Wikibase it seems possible to use it with MediaWiki.
- To make the data look more like a graph and less than a set of documents each time a field in the JSON API has for value an EntityId, an EntityIdValue or an entity URI the GraphQL API returns an Entity instead.
- The type system reuses the naming used in https://www.mediawiki.org/wiki/Wikibase/DataModel with a top interface called Value that is extended by both Entity and the different DataValues.
TODO:
- Solve the questions below
- Do a lot of optimizations.
- Implement more mutations
- See if the could merge the MonolingualTextValue and Term objects (they seems duplicate to me)
- Implement more lookups (by sitelink, by property/value...).
Questions:
- Is it moving into the right direction?
- Is the structure well designed?
- There is no way currently to get all statements (outside of retrieving the fields for all properties). We could have a fake "all" property in the StatementList and SnakList objects but it could be better to use GraphQL arguments (e.g. claims(property: ["P31", "P20"], rank: "BEST") to retrieve best statements for properties P31 and P20). Same for TermList and AliasGroupList.
- Could GraphQL and Oauth play together
- If everybody think it's great: should we implement this API as part of Wikibase, an other MediaWiki extension or a specific Wikimedia service.
TASK DETAIL
EMAIL PREFERENCES
To: Tpt
Cc: Tpt, Jonas, Ricordisamoa, hoo, Lucas_Werkmeister_WMDE, Aklapper, dbarratt, PokestarFan, Lahi, Gq86, GoranSMilovanovic, QZanden, LawExplorer, Wikidata-bugs, aude, Mbch331
Cc: Tpt, Jonas, Ricordisamoa, hoo, Lucas_Werkmeister_WMDE, Aklapper, dbarratt, PokestarFan, Lahi, Gq86, GoranSMilovanovic, QZanden, LawExplorer, Wikidata-bugs, aude, Mbch331
_______________________________________________ Wikidata-bugs mailing list Wikidata-bugs@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs