indigotech / onboard-hugo-miranda

0 stars 0 forks source link

[Track 7/9] User query #23

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

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

Step 1/3 - The query

Estimated time: 2 hours

This is the first query you're going to implement on the project. After logging in and creating user, now it's time to provide a query for fetching a user information. Some details:

  1. Query Name: User
  2. Parameter: a user id
  3. It's authenticated
  4. Response: a user type. If you created a type to return a user on the previous track, you can reuse it. If not, create a GraphQL type with all user info that can be returned

Unlike the previous tracks, now you're going to write the query prototype and integrate with the database already.

NOTE: think about the database fields you're going to return when creating the User GraphQL type. You wouldn't return, for example, the password hash, right? 👀

NOTE: don't forget to predict error cases. In this query, the most obvious one is passing an id that doesn't exist on database.

hugoms154 commented 3 years ago

finish

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

Step 2/3 - The tests

Estimated time: 2 hour

Now it's time to test your query and all its possible scenarios.

Write tests to verify it's working. Again: try to make independent tests, setting up your database before each one according to what you want to test.

hugoms154 commented 3 years ago

finish

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

Step 3/3 - Challenge: seed

Estimated time: 3 hours

[Spoiler alert]: your next track is about writing a query to list users. But in order to do that, you should have users on database (and a lot of them), right? Well, you could use your recently implemented mutation CreateUser to add them. However, this challenge is about presenting you a more efficient method, while you can learn something new: database seed.

The idea is to write some code to populate your database, creating an environment to facilitate your Users (list) query develop. Follow the steps:

  1. Create a new script on package.json and name it seeds. Leave it empty, for now.
  2. Create a file on a folder of your choice and write some code to add at least 50 users on database. This is going to be your seed script.
  3. Think about how you would make it run properly, return to package.json and create your npm run seeds command.

NOTE: don't forget that you have to connect with the database in order to run the code, right?

You can check on TablePlus if your script worked. One thing that can help you with this code is Faker: a library that has some cool features to return several kinds of randomic data you want, like names, websites, numbers, sentences, and a lot more.

NOTE 2: this is an example of task that we use the chore/ prefix on the name of the branch.

hugoms154 commented 3 years ago

finish

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

Click here for your next track