Slide 34
Slide 34 text
Why GraphQL?
query {
items {
name, image, value
requiredFor {
quantity, quest {
title, image, text
DjangoCon AU 2023 34
If GraphQL has these sharp downsides, why use it at all? Because it's
super cool for exploring deeply interlinked data. This query is looking
at 3 tables in SQL, Items, Quests, and a many-to-many through table
between them. If we were making a dedicated API endpoint for this, it
would be super easy to write a SQL query for. But what if we don't
want to build a dedicated view for every query? We could make a
view that takes in a raw SQL query and runs it, but even ignoring the
security issues with that, the data would come out as the fully
expanded join matrix and require some reshaping by clients, or the
clients would have to effectively implement the SQL join themselves.
GraphQL gives us a middle ground. Performance isn't as good as the
specific view, but it's good enough in small cases and in return we get
a generic system that can safely answer many kind of client queries.