How to Create Query for Getting User by ID in Graphql || Nestjs + Typeorm
![](https://about.lovia.id/wp-content/uploads/2020/07/5-thumbnail-getuser.png)
In this blog, we will discuss how to make a query to fetch one user by id. This’s very simple. We only gonna modify 2 files, user.service and user.resolvers
We’ll make one function with just one line of code. The code is simply finding our expected user in our database. With Typeform, the code will basically look like:<your-user-repository>.find({where: {id: <inputedID>}});
This is our example of the complete function:
async findOne(id: number): Promise<User> {
return await this.userRepository.findOne({ where: { _id: id } });
}
In resolvers, we were just gonna take the input and pass it to the function that we just created.
The query that we created pretty much like the code below:
@Query(returns => User)
async findUser(@Args({name: 'id', type: () => ID}) id: string): Promise {
return await this.usersService.findOne(parseInt(id));
}
To that, our query is created. See also the demonstration on a video of how to create a query of get one user below:
Installation for MongoDB locally on windows computer Download Mongodb Download MongoDB here. Choose the MongoDB Community Server. Run the Installer Just click next.. Edit Path Edit your environment variable in System Properties. Edit path variable on your User Variables. Add The MongoDB’s Bin folder, usually in C:Program FilesMongoDBServer4.2bin Run MongoDB $ mongod $ mongo…
Hello, today I am going to get in touch with something called API. I guess it is very familiar among people who are interested in software engineering. Let’s get started! Continuing development using Strapi First, open Command Line Interface (CLI) and change the directory to the imagerepo folder by typing : $ cd imagerepo Start…
In Strapi website, when installing Strapi using Docker, the available guide only tells you how to create a brand new Strapi app. On the other hand, they do not give a step-by-step guide how to build your Strapi app image from an existing project 😔 In this article, we are going to learn how to…
> use-case : User bisa Upload Foto Profil / KTP / NPWP requirement : service yang digunakan untuk aplikasi Image repository service bisa diupload dan diakses (view and CRUD) menggunakan RestAPI dan GraphQL Termasuk metadata (when, who, dll.). FIle yg upload disimpan di AWS S3 Tool : Strapi
So for this chance i will tell u a little bit about my experiance, i still on going to setup NSFW.js, but before we going to describing about my experiance i will tell a little bit about “what is nsfw means”. What is NSFW? The acronym NSFW stands for “not safe for work.” When used correctly, NSFW is a…
Strapi is an amazing open source headless CMS that enables developers to design API fast. It is very developer-friendly and based on my experience, it also helps developers to finish tasks in minutes, which normally costs several hours. In Strapi official website, you can see some active Strapi communities. Unfortunately, my country was not on…