osuAkatsuki / bancho.py

An osu! server for the generic public, optimized for maintainability in modern python
https://akatsuki.gg
MIT License
216 stars 132 forks source link

GraphQL API #67

Closed memsdm05 closed 3 years ago

memsdm05 commented 3 years ago

What's GraphQL

Taken straight from their website:

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data -GraphQL

Basically, instead of individual endpoints representing objects in the server (ie GET getUser/1 == Player(1)) , GraphQL processes a scheme sent my the client and fills it out with the requested data. This allows our entire api to be one endpoint. You can read more about it on their website.

Here is an example of a GraphQL request and response.

GraphQL is mainly aimed towards sending data from objects. You can request attributes of an object and it will respond with those attributes.


Why

As gulag-web requires more and more data from data, there is a need to keep creating endpoints for every unique information requested. This creates a lot of bloat and unnecessary version communication between gulag and gulag-web. A GraphQL implementation would cut down on this bloat and make development much easier. Most API transactions are about lbs, users, or other data of that nature, which can be simplified with this API system.

On top of this, the server only responses with the data requested. Systems like this would become archaic. https://github.com/cmyui/gulag/blob/b0a87c123223c5498428169c4a43a9ecd731f16f/domains/osu.py#L1563-L1584


How

Graphene is a robust GraphQL engine for python. Instead of running as a server, it processes string information you pass into it. This allows Graphene to run over cmyui_pkg. With a bit of modification, existing objects can be used by Graphene to make GraphQl schema. On gulag-web, Graphene can be used to parse responses into a dict which can be used by the program. Either way win-win.


Thoughts

While I know GraphQL for its powerful requesting functionality, I also think it can "POST" data too. Maybe we can dip our toes into GraphQL on the "GET" side before using it for posting data, idk.

EDIT: super cool demo https://api.spacex.land/graphql/

cmyui commented 3 years ago

interesting idea that will probably either be looked into directly or that will provide inspiration to some handlers i write in the future. going to close the issue for now, if anything i'd probably want to implement something like this myself, sounds like an interesting thought experiment lol.