Front End GraphQL

A rest from all that REST?

The problem with REST APIs

Sometimes you get too much info...


              {
                "username": "IAmKale",
                "password": "plaintextpassword",
                "lastLogin": "2019-01-24T12:35:49.543Z"
                ...
            

...or not enough!


                return axios.get(`${API_URL}/users/1234/`).then((user) =>
                  axios.get(`${API_URL}/profile/${user.data.profileId}/`)
                    .then((profile) => ({
                      ...user,
                      profileData: profile.data,
                    });
                  );
              

What is GraphQL?

REST < GraphQL?

Live Demo

GraphQL - Pros

  • Serve data from many APIs as a single GraphQL API
  • Reduce multiple requests into a single request
  • Empower clients to request exactly the data they need now, and additional data later

GraphQL - Cons

  • Adds more complexity to the backend
  • Caching is tricky
  • Requires additional considerations for things like request depth

References

Thank you!

Questions? Comments?