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:
> 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
In this blog, we will discuss how to make a Mutation on Graphql to Create and Modify a user. We only gonna modify 2 files, user.service and user.resolvers user.service user.resolver Mutation: Create User user.service We will create one function here to create a user, we’ll name it ‘createUser(userData)‘. We have one parameter here containing all…
Have you ever heard of API? API stands for Application Programming Interface. As mobile applications became popular nowadays, the use of API also became a standard. For example, if a company has a website and a mobile application (both Android and iOS), they are not going to create separate databases. Instead, they use API to…
Hi there! Today I will continue to develop a recent project in Strapi, called id-card-repository. If you are new, please check the previous article here. Specifically, the main topic is CRUD operations using GraphQL with Strapi. CRUD stands for Create, Read/Retrieve, Update, and Delete. CRUD operations are essential as data stored in databases dynamically change….
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…
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…