A developer adds authentication and payment microservices to a GraphQL gateway using NestJS. The process includes defining schemas, creating resolvers, configuring environment variables, and testing the federated API endpoints to ensure seamless interaction between services.
Length 14:40
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #graphql #nestjs #microservices #federation #typescript #api #gateway #coding #backend
0:00 So now that we've exposed our reservations microservice over our 0:03 GraphQL gateway, let's continue and add the 0:07 authentication microservice as well 0:10 so that we can query all the users in our system. 0:14 We'll go into the auth module and follow the same process that 0:18 we did in the reservation service. 0:20 So we'll simply add the 0:23 graphqlModule.forRoot 0:27 and pass in the 0:28 ApolloDriverConfig 0:32 as the 0:34 options here. 0:36 Now I wanna pass in the driver. That will be the 0:39 ApolloFederationDriver from nestjs/apollo. 0:43 And then we'll specify the auto schema file again, where we wanna set 0:46 federation equal to two so that our schema is 0:50 automatically generated from our code. 0:53 So in our users directory, let's go ahead and create a 0:57 new 0:58 users.resolver.ts, 1:02 and this is gonna be just like we did with the reservation service. 1:06 We'll use the resolver decorator 1:08 that will be returning the user document, 1:13 and make sure we import this from app/common. 1:16 And so we'll go ahead and export the class UsersResolver. 1:21 And our constructor will go ahead and inject the 1:24 user service. 1:28 And now I wanna add a mutation using the mutation decorator 1:33 that will return a user document. 1:37 And I wanna expose the create user method. 1:40 So here, we'll use the @args decorator again and 1:44 extract the create user input 1:48 that we'll call createUserInput, but we'll know will just be simply the 1:51 same 1:52 DTO we've already created, the CreateUserDTO. 1:56 So inside of this method, we will simply return 1:59 this.userservice.create and pass in 2:03 the createUserInput. 2:07 Next up, let's add a new 2:09 query here using the @query decorator from 2:12 nestjs/graphql, 2:14 where we'll go ahead and return an array of user 2:18 documents, 2:20 and I'll give this a custom name of users 2:25 because we'll create a new find all method here that will simply 2:29 return 2:29 this.userservice.findall, 2:34 which we haven't implemented yet. 2:36 However, we can easily implement this by going to
The rest of the transcript is for members.
Sign in