Skip to content

Instantly share code, notes, and snippets.

@d-e-v-esh
Created September 11, 2022 08:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-e-v-esh/d0c7cde2bdfecde2e265b7d63dd1c89a to your computer and use it in GitHub Desktop.
Save d-e-v-esh/d0c7cde2bdfecde2e265b7d63dd1c89a to your computer and use it in GitHub Desktop.

Google Summer of Code 2022 Final Report

This report is the summary of all the work that I did on the journal-policy-tracker-backend under the Open Bioinformatics Foundation (OBF) as part of the Google Summer of Code 2022.

I started this GSoC project from scratch, so all of the code on the dev branch (default branch) is written by me. I have also written two long blog posts that go in-depth into my journey of GSoC. I explained all the fundamental features I implemented and the difficulties that I faced while doing so.

Project Description

Merged Pull Requests

This pull request contains a working server with a basic mongoose model and typedefs for the Journal entity, the createJournal Mutation that will allow us to create a new journal and the getAllJounrals Query that will allow us to fetch all the journals that we created.

Commits:


This PR builds on the journalResolver and adds more functionalities. After this PR, we can do basic CRUD operations with the journal entity.

Those operations are the following:

  • Updated Journal model and typeDefs → Added more fields and field types to the Journal entity
  • Added getJournalByISSN Query → Allows us to fetch the details of a journal by its ISSN.
  • Added deleteJournal Mutation → Allows us to delete a journal from the database.
  • Added updateJournal Mutation → Allows us to update a journal in our database.

Commits:


This PR adds the functionality of a user authentication system on the backend. After this PR, we can register a new user, login a registered user, and get a list of all registered users. It also implements hashing and salting of passwords in the user authentication system using bcrypt.

Commits:

  • feat(user-auth): basic user auth → This commit contains the following:
    • Added User model → A file that contains the main mongoose model for the User entity.
    • Added userType → A file that contains all the types of everything related to the User entity.
    • Added userResolver → A file that will handle all the queries and mutations related to the User entity.
    • Inside userResolver, we have the following:
      • getAllUsers Query → Returns a list of all the users.
      • register Mutation → Let us register a new user.
      • login Mutation → Let us log in a new user.
  • feat(user-auth): hashing and salting → This commit adds on top of the previous commit and implements hashing and salting of passwords in the user authentication system using bcrypt.

This PR adds the functionality of session management on the backend.

Changes:

  • Because of session implementation, whenever a user registers an account or logs in to an account, a cookie will be sent to them and saved in their browser. Because of that cookie, the user will stay logged in to our website.
  • A new me query is added. It will be used by the front-end to fetch the details of the user that is currently logged in.
  • All the key values are replaced by environment variables.
  • Implementation of CORS with dynamic origin.

Commits:


This PR adds authorization on the backend using an auth middleware. Because of the auth middleware, a user must be logged in to create, update, or delete a journal. Further integration of users and journals was also added. Whenever a user creates a journal, that journal's createdBy field is populated by that user's Id.

Commits:


This PR updates the current journal schema, adds the ability to add mock data into the database with the help of mutations and adds a few additional mutations for fetching journals.

Commits:


This PR adds the functionality of role-based authorization to the user authentication system for the app. There are 3 roles that can be assigned to a user with an account which are:

  1. ADMIN
  2. MODERATOR
  3. USER

The capabilities of each role will be updated in the future as more and more functions (queries and mutations) are added to the app's backend.

I also added a journal middleware in this pull request. Now, while deleting a journal, that journal's reference will also get deleted from its creator's journals array. Before this, we would have ghost IDs that pointed to journals that were already deleted which would take up memory in the database.

Commits:


This PR fixes all the queries that returned items with pagination. Now with the paginated user / journal items, we also return the total number of users and total number of journals with the response. Knowing the total number of items during pagination is important to calculate the last page of items on the front-end.

Commits:


This pull request adds the feature of testing in our backend project using the Jest library.

I was having some difficulties and got stuck in a few places while setting up the testing server. One big problem that I faced was when I was using mongoose.createConnection() to connect to the database. It is supposed to return me a new connection but doing that isn't compatible with the mongoose models as explained in the answer to this StackOverflow question. So I decided to go back to mongoose.connect() and call .dropDatabase() just before the tests start. This provides us with a clean slate for all the tests to run.

Commits:


This pull request adds the documentation of all the schemas as well as queries & mutations that I've added to the backend. The documentation website is built with Docusaurus.

All the queries and mutations in the documentation have sample source code under them that is displayed with the help of tabs in Docusaurus. It shows an Operations tab that contains the input query that will go in the GraphQL server, a Variables tab that contains the input variable values that are needed for that query to run and the Response tab that shows the output that the server will respond with.

Current Documentation Link

Commits:


Goals and Future Work

I have completed all the mentioned goals in my proposal except the deployment part. I'll be able to do the deployment as soon as I get access to a server on a cloud from my organization. My next task after the deployment of the server will be adding more and more features to the backend. Some of those features will be Change Password, Forgot Password, Email Verification and User Mutations where people can change their account details.

Acknowledgements

I would like to sincerely thank my mentors, the OBF community, and Google for giving me an enriching experience this summer. I am extremely thankful for the opportunity to participate in this program. I am immensely grateful to Yo Yehudi and Pritish Samal for their constant guidance during this entire duration of GSoC.

Post GSoC

Contributing to OBF has been amazing and I intend on continuing my contributions to the project. I would also review other contributors' work and help maintain the project to make it even better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment