indigotech / onboard-hugo-cruz

0 stars 0 forks source link

[Track 2/7] Server Setup #4

Open taki-tiler-server[bot] opened 4 years ago

taki-tiler-server[bot] commented 4 years ago

Step 1/6 - Create a git branch

If you don't remember how to create a branch, check the references in the previous issues.

Note: From here, the issues will contain fewer tutorials and step-by-step guides. However, it doesn't mean you won't be able to ask. You can always ask anything to any Taqtiler. We are here to help 😉

hmartinsc commented 4 years ago

next

taki-tiler-server[bot] commented 4 years ago

Step 2/6 - GraphQL setup

Estimated time: 3 hours

In this step you'll have two main tasks: create a node project with typescript and setup a graphql server. But before you start, there are some core concepts you need to know in order to understand what's going on on your code. Try to do some research on your own about these topics, but feel free to ask your tutor, or even another Taqtiler, for references, tips and/or clarifications:

  1. Client-server architecture
  2. HTTP communication
  3. REST
  4. GraphQL

You can both setup these by yourself as showed in this tutorial or use a cli to make this whole setup for you as shown here (we won't tell anyone 🤫). But remember: using this kind of setup doesn't mean you shouldn't know what's going on on that code.

After the setup, you should be able to access the Graphql docs, either on browser, Graphiql or Graphql Playground (you can choose the one you like) and successfully write some GraphQL queries/mutations. You can use the Hello query of the setups above to verify your server is working. Keep this query for future testing!

Note: For now on, some steps will have an estimated time to help you organizing your time better. If you do not finish the step in the estimated time don't worry! It's just an average time based on previous onboards. The main purpose of it is to indicate when you should ask for help in case you're stuck.

By the way, remember that if you're struggling with any topic, feel free to ask any Taqtiler ;)

hmartinsc commented 4 years ago

next

taki-tiler-server[bot] commented 4 years ago

Step 3/6 - Create a Pull Request

If you don't remember how to open a Pull Request, check out the references in the previous issues. Your PR should have develop branch as base, to be merged into later.

This pull request will be reviewed by your Taqtile tutor and possibly by some other people. This process is called Code Review (CR). You can ask your tutor who will be revising your code.

Make sure you're marking them on every Pull Request as reviewers. Check here for an example of Code Review. You'll possibly have some changes requested/suggested in order to merge this new branch on develop.

After opening the pull request, you can continue your work on a new branch.

hmartinsc commented 4 years ago

next

taki-tiler-server[bot] commented 4 years ago

Step 4/6 - Containers everywhere

Estimated time: 2 hours

[Spoiler alert]: in the end of this onboard, you'll basically develop a CRUD of an entity called User. So, in order to store the user data in our app, let's create a real database.

The database we use on most of our projects is PostgresSQL, an open-source relational database.

Creating the database containers

There are a lot of setup so far right? In order to reduce the project setup time, we use Docker containers to create a database to work locally while developing. We'll create 2 databases: one for running server locally and another for (spoiler alert 2) the tests. Yeah, we will write tests. 🤓

First, make sure you have Docker installed on your machine. Just hit Command Space and type Docker. If not, you can download on their site.

  1. Create a docker-compose.yml file on your root project folder.
  2. Setup the two databases in the docker-compose.yml file. You can use this example if you want, just replace the values on environment fields.
  3. Run $ docker-compose up -d on terminal to mount your containers.

Note: Before run docker-compose commands, make sure that the docker is running on your mac. You can use again Command Space, type Docker and hit Enter.

Note 2: If you want to stop your containers, you can run $ docker-compose stop command in your project's root folder.

hmartinsc commented 4 years ago

next

taki-tiler-server[bot] commented 4 years ago

Step 5/6 - Using database's data

Estimated time: 3 hours

In this step, you'll connect your code with the database and create your first table using only Typescript 😎.

Connecting with the database

Do we have a library to access our database? Of course we do. For this, we use the TypeORM library. It helps us to make database operations (create tables, access data and so on) in a very simple way.

  1. Take some time to learn how this library works. It's super cool, but it's also a lot of abstraction.
  2. Follow their docs to add it to your project (remember that we're using postgres).
  3. Choose an option provided by typeorm to connect to your database. The credentials are the ones you set on docker-compose.yml.
  4. Try to connect with database before running the yoga start code. For now, you can connect only with your local database, leaving the test connection for later.

Note: don't forget to check if your docker container is running before connecting to the DB, otherwise it will fail.

Now you can ask: "Do they have a tool to manage the data inside the database without code?" Of course we do, young padawan. Actually, we recommend these two apps:

Feel free to choose one of these above, or any other app you want :D

Creating your first entity

After successfully connecting TypeORM to your database, it's time to see it working by creating your first table. Guess what? It will be called User (we told you so)

  1. Check on TypeORM docs how to create a TypeORM entity
  2. After creating the table, try creating a row (an user 🙆‍). You can do this either coding (it's possible) or directly on Tableplus, whatever you prefer.

Note 2: too much for one step? Don't get stuck and feel free to ask anything to any Taqtiler 👍

hmartinsc commented 4 years ago

next

taki-tiler-server[bot] commented 4 years ago

Step 6/6 - Rebasing your branch

Here in Taqtile, before merging our revised (and approved) branches, we rebase it into the one we are attempting to merge. In this case, you'll rebase feature/setup-graphql to develop.

Too confusing? Here are some good links you can read about rebase:

Note: after your feature/setup-database is approved, you'll repeat this process.

hmartinsc commented 4 years ago

next

taki-tiler-server[bot] commented 4 years ago

Click here for your next track