DEV Community

loading...
Cover image for Quickly create a POC/MVP with GraphQL and NodeJS!

Quickly create a POC/MVP with GraphQL and NodeJS!

vincentdesmares profile image Vincent ・4 min read

Discover graphql-sequelize-generator and the magic of schema-generated GraphQL!

Tldr;

Graphql-sequelize-generator is a library that will help you to quickly setup a Node.js POC/MVP with Sequelize and GraphQL.

We want a POC, and we want it now!

When we started to work on Teamstarter we wanted to quickly test it on our user base and see if the concept worked. We needed a very simple implementation of the core of the concept, a private crowdfunding platform for organizations, a proof of concept (POC).

Usually, when I do a small POC of a random idea, most of the time it ends up as a dead repository on my Github after a few weeks, like an ECS based on redux or a procedural generation library based on Postgis. Many ideas, low energy: Motivation is bitch 😩.

I learned through a painful experience that the quicker I produce a POC, bigger is the chance I kept some motivation to iterate on it and make something of it at the end.

But being fast is sometimes not enough. From times to times, I get super motivated after reading a tweet or an article and search for an old repository to get it back on his foot. Sadly, most of the times my β€œfast and ugly" code prevent me to do so by being impossible to understand! 🀬😭.

To sum up, in my experience, a useful POC is:

  • πŸƒπŸΎβ€β™€οΈ Created quickly
  • πŸ“š Simple to iterate on
  • πŸ‘€ Easy to understand and pick up after having forgotten about it

Is GraphQL a good fit for Proof of concepts?

GraphQL is amazing for many reasons (here, here and here) and is a top choice for efficient API development nowadays.
Yet, even if it might generate a nice and easily understandable API, it is most of the time painfully slow to setup and extend compared to REST πŸ₯΅.

The setup is slow because you have to spend time describing your schema field by field, while there is a huge chance you already did it in your ORM.

The addition of new endpoint is slow too as GraphQL only describe what a resolver(link) is and not basic methods to fetch the data in your database.

After a few painful POCs we decided to work on tools that could help on the two last points, setup and extendability.

Alt Text

What is GSG?

From those problems we created graphql-sequelize-generator πŸŽ‰
The setup is way faster by using the definition of the ORM (Sequelize) to generate procedurally the endpoints. We do not generate a full schema by default, it’s up to you to decide what do you want to expose. But it only takes 3 lines of code!

The extendability is solved by using graphql-sequelize and custom made create/update/delete mutations.
We also provide a lot of hooks and advanced options that you can discover in the documentation.

Get started in 2 minutes

We made 2 boilerplates: In javascript and Typescript to quickly create a create-react-app application backed by NodeJS and Express.

For both we tried to reduce the setup to a bare minimum:

$ git clone git@github.com:teamstarter/gsg-boilerplate.git; cd gsg-boilerplate
$ nvm use
$ yarn
$ yarn db-reset
$ yarn dev
Enter fullscreen mode Exit fullscreen mode

And you’re good to go!

What’s next? What about the MVPs?

We did not intend to develop something that could do more than a POC as deeply nested queries tends to end in a huge amount of database queries.

But surprisingly, thanks to our configuration of grapghl-dataloader your POC can become an MVP without any problem! πŸ₯³ By hooking on Sequelize query hooks and batching the intercepted requests, the query count is kept to an acceptable level.

To make is easier to understand you will find below a small visualisation of the problem and the solution ✍️

Alt Text

We are currently using it in production with a Postgres AWS medium database, with more than 20000 active users per month and have no performances problems! πŸš€
Also, due to its minimal code footprint the maintenance is really easy and simple 😊

Thanks for reading!

We are using GSG every day and we hope that some of your next ideas will avoid the Github graveyard of the forgotten projects! πŸ™

If you have any problem with the lib or the boilerplates, do not hesitate to open an issue on Github or submit a PR!

Links

If you want to discover GraphQL :

More about GraphQL-Sequelize-Generator

We're hiring

You are a junior dev able to work in Paris quickly? Reach us!

Discussion (0)

Forem Open with the Forem app