serializator / hypixel-api-with-graphql Goto Github PK
View Code? Open in Web Editor NEWA web service using Express and the GraphQL middleware to access the Hypixel API with GraphQL.
License: MIT License
A web service using Express and the GraphQL middleware to access the Hypixel API with GraphQL.
License: MIT License
When a request is made to the GraphQL API with a recursive data structure it might cause many unnecessary requests being made to the Hypixel API when we could've cached them.
An example of a recursive data structure to request the friends of a player and their friends for something like friend #suggestions.
{
player(uuid: "4ff6ea51-1cff-4018-923c-fb3a71c254b1") {
friends: {
friends: {
uuid,
displayName,
lastLogin
}
}
}
}
Facebook DataLoader to the rescue.
It's a read-through cache with a clear explanation for GraphQL specifically.
Games in the API response from some of the endpoints at https://api.hypixel.net/...?key={key}
are represented by numbers, a numerical identifier that is unique to a specific game.
A table with game types and their various identifiers can be found here!
I say "some of the endpoints" because the API response from https://api.hypixel.net/players?key={key}&uuid={uuid}
uses the database name of the game instead of the numerical identifier I mentioned earlier.
When an API response uses the numerical identifier the custom scalar type will be used to transform it into a readable form.
In the HypixelDev/PublicAPI repository a markdown file (linked earlier) exists with a table that associates the numerical identifiers with their corresponding readable names.
Local Copy
A local copy of the information (a switch) that returns the readable name can be used to prevent the necessity of another network request and parsing of the markdown file, but has to be updated regularly.
Network Request & Parsing
A network request is more safe in terms of preventing stale data that might occur because of the local copy but requires a caching layer so that we don't make to many requests to the API.
Facebook has the DataLoader that acts as the caching layer between the data layer and GraphQL.
It also requires is to do some parsing on the markdown file to turn it into a key-value structure with the key being the numerical identifier and the value the readable name of the game.
When a GET
request is made to https://api.hypixel.net/boosters?key={key}
, the JSON response has a nested array named boosters
with (according to the reply implementation for the booster type in the Java project from the HypixelDev/PublicAPI repository) 7 consistent properties:
Aside from the consistent properties, a property named stacked
can exists but does not always, and can be an array of strings or a boolean.
If stacked
is non-existent this means that that booster is the only booster of its type that exists at that moment.
If stacked
is an array of strings this means that there are other boosters of the same type in the queue to be activated after the booster itself expires.
If stacked
is a boolean this means that it's a booster that's in the queue (stacked
as an array of strings) of another booster.
With this information we can create a GraphQL schema definition that correctly conforms to the API response, though with a slightly different data structure because fields in GraphQL can't have multiple types.
type Booster {
id: ID!
parent: String
purchaser: String!
amount: Float!
original_length: Int!
length: Int!
game_type: Int!
date_activated: Float!
queue: [String!]
}
In the API response from https://api.hypixel.net/friends?key={key}&uuid={uuid}
, friends are represented as an array of objects with each three properties, the UUID of the person who sent the request, the UUID of the person who received the request and since when the friendship started.
A friends: [Player!]!
can be added to the Player
object type, which then would be fetched recursively in the same way that a single player would be fetched.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.