DEV Community

Cover image for How to Read or Understand an Open-Source Projects

How to Read or Understand an Open-Source Projects

It's always supper fun to dig into coding and try to make sense of open-source libs. it's been a while since I've started to use nestjs-query in my GraphQL services. It makes a lot of things easier. But I was puzzled with how the underlying implementation for Connection pagination and offset pagination works.

So I dug the lib and here is my final understanding: https://github.com/TriPSs/nestjs-query/issues/344#issuecomment-2562805549


I do not think it is gonna find its way into the docs someday, but nonetheless I decided to let you know how I get started to work with a new concept (GraphQL) and read this libs codebase in a manner that helped me to understand what's going on:

  1. I started with getting familiar with the structure of the root directory in nestjs-query. Just seeing what we are using and what we have.
  2. I felt I kinda missed some crucial parts of docs. So I went to the official docs and read a bit more about the packages that resides in this monorepo.
  3. I came back and ran one of the e2e tests in the debug mode. In fact I added plenty of breakpoints in my VSCode and tried to see how it works in general.

    I was really interested in knowing how it generates the resolvers, service layer and integrates with TypeORM.

  4. Now I had a pretty good idea about how it works but I still was not able to pin point where exactly in the codebase we are defining the default pagination strategy. That's where I went back to the docs and read it this time top to bottom once more.

  5. That's when I started to comprehend more and see how it work. Surprisingly it was really a no-brainer, I do not mean it is simple, I mean why they choose to implement certain things the way it's done in the lib. E.g. this lib is using mixins extensively and I love how modular it has made this lib as a result.

  6. Eureka moment. I finally grasped it.

NOTE

In this process I can tell you that I several times went back and forth, ran the e2e tests in the debug mode again and again to understand it. So if you tried to apply this approach and did not get the result you wanted do not be discouraged and try yet again.


BTW if you wanna develop a new GraphQL service in NestJS it is a really great tool to do the mundane and dull tasks with nestjs-query. So that you can focus on building what matters for your business.

And besides the fact that I am using it, I am actively as you can see invested in this lib and in fact my aim is to make it something comparable to HotChocolate as I explained it here: https://github.com/TriPSs/nestjs-query/discussions/333

And if you liked this post consider giving this repo a star on GH :).

GitHub logo TriPSs / nestjs-query

Easy CRUD for GraphQL.

Nestjs-query Logo

Test codecov Known Vulnerabilities slack

nestjs-query

Nestjs-Query is collection of packages to make crud for graphql easier.

Why?

While working on projects in nestjs it was very easy to get up and running with graphql however, there were many patterns that were common between the resolvers. In particular querying, sorting and paging.

Installation

Install Guide.

Docs

Packages

Nestjs-query is composed of multiple packages


Follow me:
Instagram: https://www.instagram.com/node.js.developers.kh/
Facebook: https://www.facebook.com/kasirbarati
X: https://x.com/kasir_barati
YouTube: https://www.youtube.com/@kasir-barati
GitHub: https://github.com/kasir-barati/
Dev.to: https://dev.to/kasir-barati
LinkedIn: https://linkedin.com/in/kasir-barati

Top comments (0)