How to Create Query for Getting User by ID in Graphql || Nestjs + Typeorm

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:
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…
From our previous blog in making a register page with React js + Ant Design (see.. http://about.lovia.id/3-easy-step-to-create-signup-form-with-ant-design-reactjs/), for now we’re gonna connect it to our Strapi Backend and make it functional. The frontend is using the miluv-pwa repository and the backend is using lovia-profile repository. The core thing that we need to do is we…
Hello there! In this post, I would like to use and demonstrate authentication and authorization/permission features in Strapi using Postman. Continuing development using Strapi First, open Command Line Interface (CLI) and change the directory to the imagerepo folder by typing : $ cd imagerepo Start yarn using : $ yarn develop Note : If you…
Strapi contains a feature in which anonymous and otherwise non-sensitive data is collected. Like any other software, the main aim is to provide the best experience to users. “ What data is collected ? “ Unique project ID (generated with UUID) Unique machine ID (generated with node-machine-id) Environment state (development, staging, production) System information (OS)…
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…
Strapi GraphQL series is back! In the previous post related to Strapi and GraphQL, in a project named id-card-repository I did CRUD operations without being authenticated which is dangerous enough as it enables all users (public users) to modify data. Today, I would like to implement authentication and authorization so only authenticated users can conduct…