Last time we looked a bit at neo4j and the benefits of using it together with GraphQL and I briefly mentioned a little thing called the GRAND stack and promised to get more into its details later. So this time let's go deeper and check out what using not two but four technologies together can do for us. The GRAND stack is a full-stack framework for making GraphQL apps, a combination of four technologies which make up the acronym:
GraphQL, React, Apollo and Neo4j Database.
For those curious, yes you can substitute React for another framework like Vue or Angular if that’s your preference, but that would make it a GVAND or GAAND stack which isn't nearly as catchy so bear that in mind.
If you’re here you probably know a bit about GraphQL already so let’s get to why GraphQL is used here. Its Schema Definition Language is language agnostic which makes it perspect for interacting with other technologies (like the ones in the stack) and more importantly its namesake graph aspect plays really well into the fact neo4j is a graph database and that means its graphs all the way down from start to finish. To summarize:
- data layer agnostic, GraphQL can be used with any data source
- no under or overfetching, querying with GraphQL gets you exactly and only the data you asked for
- graphs all the way down, all data is handled as a graph and since its data source agnostic you can use this to integrate data from different sources in a transparent and organized way
- introspection, you can ask a GraphQL API for the queries it supports which makes creating documentation a lot easier if not automatic with certain tools like SpectaQL
Neo4j is the key fit here because it's a graph database so it's made specifically for handling graph data and complex graph traversals which is exactly what we have with GraphQL and its queries. This also means we’re able to maintain the same data model throughout the entire stack. Now if you’ve read my last piece about Neo4j you’re probably thinking about having to learn Cypher. The good news is you don't have to do it straight away thanks to the neo4j-graphql.js package. It handles building basic mutations for you and it also solves the n+1 query problem as well by translating GraphQL queries to a single Cypher query.
You could say it's called grand for a reason as you will have to learn Cypher to fully grasp the GRAND stack and that can take a while, especially if you haven't dealt with it before. It is a lot of work and that can be a turnoff, but if you do it's probably worth it just for the neo4j graph database, never mind the whole stack so if you’re already working with GraphQL that could be a nice goal to set for yourself. If not, even without it, it does offer you quite a bit and is probably worth checking out to see if you want to invest your time and work into learning it. If you want to learn more about it make sure to check the GRANDstack official documentation.
A guest blog post for GraphQL Editor blog by Michał Tyszkiewicz
GraphQL Editor is a supportive tool for both advanced GraphQL users as well as those taking their first steps with GraphQL APIs. Our all-in-one development environment for GraphQL will help you build, manage & deploy your GraphQL API much faster. Try GraphQL Editor for free!