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):

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
https://phabricator.wikimedia.org/T173214

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Tpt
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

Reply via email to