-
I'm reviewing Gatsby for my employer, and I have a question that I can't reply on my own. I've read all I could find about GraphQL in the docs, as well as issues #420 and and #4994, and found this remark from @KyleAMathews:
My question is: what optimizations have been implemented / planned, and in general what kind of optimizations are possible? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
@abaco Good question. One of the biggest benefits of GraphQL is the fact that it prevents both under-fetching and over-fetching. What this means is that the data that is present in your site's bundle ends up only being the keys you specify in your GraphQL queries (which you use in your components). This prevents the common issue where we tend to load more data than what is used in web projects, leading to a slowdown in load times etc The other advantage (not an optimisation per se) that GraphQL affords in Gatsby specifically is that it enables fetching data from multiple services or data formats (via plugins) in a conveniently coherent way. You don't need to write API calls for respective APIs of services for data that you'd like to use at build time. They are all available (via gatsby and its plugins) in GraphQL. This makes access to data simpler as well. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Some examples of what's possible:
This is just what immediately came to mind. Also, to clarify: I partially agree with your attitude on this topic and currently we don't utilize the power of declarative queries and schema to its full capacity. But also as @herecydev mentioned - JavaScript API for data-querying will likely be unique to Gatsby. So it won't help much with the learning curve + this learning will be only useful for Gatsby projects. |
Beta Was this translation helpful? Give feedback.
Some examples of what's possible:
Declarative data requirements may help us to eventually switch to lazy sourcing mode (for develop and per-page builds). By analyzing your page query we can figure out which data this page needs before we actually have this data available in the local storage. Then we can ask source plugins to
source
data required for this page only (and postpone sourcing everything else).Someday we may have Gatsby GraphQL available as a remote service as well. In this case, all the network-related benefits of GraphQL will be also important.
We can hook external GraphQL APIs into Gatsby schema and provide a u…