Git Product home page Git Product logo

hypixel-api-with-graphql's People

Contributors

serializator avatar

Watchers

 avatar

hypixel-api-with-graphql's Issues

Caching Layer

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.

Game Object Type

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.

Booster Object Type

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:

  • _id: string
  • purchaserUuid: string
  • amount: decimal
  • originalLength: integer
  • length: integer
  • gameType: integer
  • dateActivated: long

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!]
}

Thread about boosters on the Hypixel forum

Friends -> Player Object Type

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.