GraphQL Apollo Server with Node. js, MongoDB - GraphQL API | RapidDev Pro | Skillshare
Drawer
Search

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

GraphQL Apollo Server with Node. js, MongoDB - GraphQL API

teacher avatar RapidDev Pro, Full Stack Developer & Tech Entrepreneur

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Introduction

      1:12

    • 2.

      Tools and Installation

      1:26

    • 3.

      Promise vs Async Await

      13:33

    • 4.

      Spread Operator

      9:04

    • 5.

      Object and Array Destructuring

      6:03

    • 6.

      What is GraphQL

      3:20

    • 7.

      GraphQL Schema Basics

      7:44

    • 8.

      GraphQL API Overview

      1:43

    • 9.

      Setup GraphQL Server

      9:58

    • 10.

      GraphQL Playground Overview

      3:34

    • 11.

      GraphQL Resolvers and Type Modifier

      3:47

    • 12.

      User and Task Schema/TypeDefs

      2:32

    • 13.

      Task List Query Resolver

      6:47

    • 14.

      Field Level Resolver

      7:35

    • 15.

      Get Task By Id Query

      4:28

    • 16.

      Get Users List and Get User By Id Query

      5:25

    • 17.

      Create Task Mutation

      5:19

    • 18.

      Modularize Resolvers

      4:36

    • 19.

      Modularize Schema ( Schema Stiching )

      8:54

    • 20.

      MongoDB Connectivity

      4:29

    • 21.

      User and Task Mongoose Schema

      3:47

    • 22.

      Signup Mutation

      13:06

    • 23.

      Custom Date Scalar Type

      3:07

    • 24.

      Authentication: Login Mutation

      9:31

    • 25.

      Resolver Context

      4:33

    • 26.

      Verify Token and Set Auth Context

      10:20

    • 27.

      Combine Resolver/ Resolver Middleware

      4:01

    • 28.

      UPDATING: Get User By Id

      6:39

    • 29.

      UPDATING: Create Task Mutation

      6:51

    • 30.

      UPDATING: List Task and Get Task By Id

      15:23

    • 31.

      Update/Modify Task Mutation

      4:32

    • 32.

      Delete Task Mutation

      4:15

    • 33.

      Offset Limit Pagination ( Task List )

      2:48

    • 34.

      Offset limit Pagination Vs Cursor Based Pagination

      5:26

    • 35.

      Cursor Based Pagination ( Task List )

      16:18

    • 36.

      Data Loaders - What and Why

      8:55

    • 37.

      Implementing Data Loaders

      15:36

    • 38.

      User Subscription

      9:42

    • 39.

      Format GraphQL Error Response and Query Variables Overview

      4:08

    • 40.

      SOURCE CODE

      0:24

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

374

Students

--

Projects

About This Class

Build GraphQL API with Apollo Server in Node.js, Express, and MongoDB Database.

GraphQL API Server with Apollo, Node.js, MongoDB. Jwt Authentication, Cursor Pagination, DB Query Batching & Caching


ÏŸ What is GraphQL?

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

♦ Ask for what you need, get exactly that.

♦ Get many resources in a single request.

♦ Describe what’s possible with a type system.

♦ Move faster with powerful developer tools.

♦ Evolve your API without versions

♦ Bring your own data and code

ÏŸ Who is using GraphQL?

♦ Facebook, Github, Pinterest, Shopify and more

ÏŸ What is Apollo Server ?

Apollo Server is the best way to quickly build a production-ready, self-documenting API for GraphQL clients, using data from any source.

It's open-source and works great as a stand-alone server, an addon to an existing Node.js HTTP server, or in "serverless" environments.

Apollo Server implements a spec-compliant GraphQL server which can be queried from any GraphQL client, including Apollo Client, enabling:

♦ An easy start, so front-end and back-end developers can start fetching data quickly.
♦ Incremental adoption, allowing advanced features to be added when they're needed.
♦ Universal compatibility with any data source, any build tool and any GraphQL client.
♦ Production readiness, and what you build in development works great in production.

You will learn the following things in the course:

♦ Build GraphQL API with Apollo Server in Node.js, Express and MongoDB.

♦ Add JWT Authentication in Apollo GraphQL API.

♦ Implement Faster pagination with Cursor Based Pagination Strategy. Will also implement offset limit pagination and will compare them.

♦ Add Data Loaders to return data faster from server with batching and caching your database query.

♦ Feel Confident with GraphQL Concepts such as Query, Mutation and Subscription.

♦ Best practices in GraphQL and Build Scalable API with proper schema design.

♦ Efficient and scalable GraphQL Schema design strategies.

♦ Learn to handle deep nested GraphQL Query.

♦ Learn to efficiently use GraphQL Playground tool.

♦ Get good understanding of schemas, "types" in GraphQL.

♦ Learn to setup real time communication between client and server with subscription.

♦ Learn to manage authentication context in GraphQL.

♦ Secure/Protect various query and mutation with Graphql Resolver middleware and auth state from context.

♦ Define relationships between various object types.

♦ and much more.

Who this course is for:

  • Developers looking to learn and master GraphQL and build GraphQL API in Nodejs with MongoDB

Meet Your Teacher

Teacher Profile Image

RapidDev Pro

Full Stack Developer & Tech Entrepreneur

Teacher

Hello, this is RapidDevPro.

I am a Full Stack Developer, Tech Entrepreneur. Working full time building software projects for 8 Years in cutting edge technology for various clients. Lead team of software engineers on multiple projects. I am sure you will learn lot of concepts from my classes which i have learned over the course of years.

Thanks, see you in my classes.

See full profile

Level: All Levels

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction: Hello, everyone. And welcome to my course on building drafty labia in Norges with a policy work on mongo db a star database. My name is Robert Probe, and I'm going to were instructed in the schools. So in this course, we're going to build the graphical a policy were from scratch and will cover all the graphical phenomenal such a square ease, mutation, subscription resolve or context, type relations and more. We're going to build many years in graphic you're using Korean mutation on. We will also add the authentication an alteration to secure our AP eyes on. We'll also learn how to efficiently handle deepness straight quarries. You are also going to implement powerful and performance cars are based pagination, and it is going to be really faster and more efficient as compared to the officer limit imagination. They're also going to make the response time faster with patching and cashing using the data Lord a celebrity. So these courses for anyone who is looking to build very designed performing graft, your labia with Apollo Server in George's and Montgomery Bizarre database, and I'll see you in my first lesson 2. Tools and Installation: Hello, everyone on in this video, we're going to see how can you download some of the lab? But it is and the tools that we're going to use in this course. So the first thing that I want you to download is the Mongo DB itself, So don't know the motive is in place. Such down lord center mongo db on Dhere, you have to basically it's like this sort of war on here. I want you to select the Mongo db communities over not the enterprise that were on select your operating system on them were downloaded. And once you're done installing, simply called the terminal on Discovered, which is mongo. So you will enter the mambo shell. And if you're able to do so, that means the mongrel is installed properly on your system. Next hour. Noodle nordea. Norges. So if you basically visit nor just or warty on go there download section, you will find binaries. For with this operating system, simply choose your operating system on down would defile. And once you're done with the insulation, simply done this common, which is north hyphen V, which, like the Nordic origin and then PM, hyphen me to check the in print version. So that's all you need to do next. I'm using the V s scored a za coordinator, so you can simply don't know that also, And as far as criminal is concerned, I'm using the come under terminal for Windows. You can download it from here, so simply sorts for commander Terminal on you will be still go over here and you can download and use it. So there is. That's it for the tools and installation on I hope you were able to follow along and thank you so much for watching this for you. 3. Promise vs Async Await: Hello, everyone on in this video, we are going to understand how they think of it. Differs with the promises. And how can you work with the single right? OK, so I'll just explain you by example. So let me this create a file over here called us is in Kobe. It okay? And you can name it whatever you want. So first of all word I'm going to do is I'm going toe create a promise which is going to guide result after three seconds. Okay, so those three second can be any icing task in the world. Example such as an a p A call to us over which is taking some time to get the response. Okay, but here, I'm just going to make it off the set time old method which is going toe simply return the result after three seconds. So, first of all, let's create the promise. Okay, on, we're going to work with this promise. First on, as soon as we're done with the promise than level one video. Single bit. So there you can clearly on the understand the difference between the think of it and the promises. Okay, so for stole here. I'm going to create a promise card as display message. Okay, so there's basically returns new promise, Okay? And the force argument is always result. And the 2nd 1 is Did eject. Okay on. I'm goingto make use off the September method over here, so I'm going to simply suspect emote. Okay, so this receives a call back, so this callback is going to run after three seconds. OK, so here we specify their timing milliseconds, hands 3000. So here I am going to simply it is all the promise. Okay, So I'll resolved with a message which we will get as a parameter toe this particular function. Okay, spaced it over here. Now, the way you can simply work with the promise is by calling this function okay on you will get it, then call back. Okay. On inside of that called callback. You will get the dessert as soon as this promise is fulfilled. Okay, So, in this desert, let us simply console log this popular dessert. Okay, on as far as the pedometer is concerned, let me just simply pass Hello. Okay. So hopefully this makes sense. Now let me open up terminal that I'm going to simply say North unsinkable torches so you wouldn't see it right? After three second, we will get out of my search and we just Hello? Okay, as you can see now let's assume that we want to bring more message. Let's say we want to make more vehicles, OK? Once we have this result. Okay, So the idea is to only make another promise, Saul, when the 1st 1 is the result. So the way you can do it is by running your task in this call back only. OK, right. If you do anything right after this, it is going toe ground radar. We write, for example, let me just simply print any log and let me just employed on this file, okay? So as you can see, this is printed right over here because this task is running a synchronously on. This is the callback which is executed when this task is done. Executing right? So when you took put our second card in this call back only Okay, so here I'm going to simply say again, display message. And this time I'm going to pass death. Okay. So again we will get it then called back. And then again, we'll get the dessert. Okay, so here also, I'm going to simply console log the results. OK, on in sort of this call back. I'm going to make another call to this function. Okay, Let me to simply the messages wassup on. We'll get the results over here. OK, so now what will happen is first of all this promise with lexical on after three seconds will get the hello. Then I get after three seconds, Will get did there. Okay. And then I'll get after three seconds, we'll get the What's up. Okay, so they destroyed with on this now, right? So we got all of this three message. OK, But the problem with this is that we are basically and bringing to the callback help problem. Okay, on this is one of the biggest problem when working with a singleness task in JavaScript. Okay, so you end up being in called back. Hell, right. So let's say you have five more calls, right? So just imagine what kind? Of course it would look like, right. And if any of the promise fails, then we need to up, like, catch, block, toe each and every promise, right? Because we never know which promises going to get rejected. Right. So what we need to do is we need to apply catch block. Okay, which receives the other object. Okay. And we need to bring this era right over here. Okay. ATM. It'll Buddhists for each and every promise called. Right. So let me this copies based on the well heeled and Mr Door here has been right. So now you can see that how are court is looking? It is basically ended up in the callback. Hell, right, so this is not a reliable court. Okay, so the a think of it, keyword basically allows you to work with the promises on it makes your court more readable by making your court look very cynical nuts. Okay, so this is off course looking isn't gonna score right, because we have a lot of call backs over here, but like to see how can you work with the think of it on, do the same thing over here. Ok, bring the same message is okay, so remember that the thing of it works with the promises only. Okay, so, first of all, I'm going to create a function. Okay, so for example Const my function. Okay, on in this function, I'm going to call this promise display. Miss it. Okay, so the way you can call the promise with the easing of it keyword is by first awful writing the overt keyword. Okay. And then you need to specify your promise, which is display message. Okay, on off course it is expecting an argument. So I'm going to pass the hello as well. Okay on. Always remember there to make use off off key word. Your function. It's to be a sink. OK, so wherever you're writing the await cable, your function, it's to basing. So I'm going toe put the sink people over here, okay? And I can simply get the result were here like this. Okay. In fact, what I'm going to do, I'm going to declare of it. Results over here, which is going to be empty. String is off. Now on. I just get saying this resort to this particular variable. Okay? Now, what I need to do is simply again called the display message, okay? And just passing the my sister. I want to pass. So here this time I want to pass there. Okay. And I can again simply assigned the desert. So this particular variable okay, on again, I can do the same thing with Newman. Said if it is wassup. Okay. Now, important thing to note here is that this is in call Will only exclude once this is fulfilled. Okay, so that's the beauty about the thing of it. So the of it is actually going toe stop the control flow moving forward until and unless this particular promise is either results or reject. So that is the most important thing about the thing of it. Hence we don't end up in the callbacks, right? Because this is basically waiting until and unless this problem promises resort. Okay, so our control flow is not going to move forward. And let me add the console log over here so that you can see properly those sequence off execution. So here I bring the result over here. Simply copy this, print it again and print it again. Okay. And let me simply commend the promise out so that you can, of course, see properly. So let me to save this on alleged go over their terminal. Okay, clear the console. and run this file. Okay? And I think I forgot to call this function. So let me just simply call dysfunction as well Over here at the bottom. Now, on this file on hit. Enter. So let's see, What do we get? We got the result as hello for civil over here. Then we got there and finally we got B. What's up? Okay, now you can yourself compare the court difference it brings. When we woke the promise and when we worked with the think of it, this court is extremely straightforward and readable to the developers as compared to this one. Okay, so you can imagine how easy and efficient it is to work with these. Think of it. Keyboard rather than the promises. Okay, on. Even if we talk about the error handling, it is so much better in case of a single bit as compared toa the promises. As you can see here, I have to apply the catch block to each and every promises, right? Okay. The reason is that any off this promise can get rejected, right, But in case office innovate, the overhead keyword throws theater as an exception. Remember, this promise is rejected. Okay, So what you can do is you can handle the exception using just single try gets block. Okay, So let me show you what it looks like. So let me. I did write gets blocked as well on. All I need to do is simply bring theater over here in the console log. Okay, so let me just do it on. Let me just take everything from here, okay? And pasted over here. So now if any off this promise is rejected than it can be simply handled over here in this sketch block, OK? So as you can see how good your core looks when you work videos, think of it as compared to the promises. Okay? And let just even try. Do it on a scenario to show you the other case. So let me just come in this out. So let me this even show you an example how this cage block will be executed. So let's on this particular promise. My number divorce up messages saying we need to basically reject the promise. So here I can simply say if the message is required. So what's up then? Simply rejected on simply Say something went, but all okay on here are also I'm going to our didn't statement so that the court blocks is not executed for that. Okay, So letting us embassy of this large garbage terminal on dry road on this fight, so you will see that force will get the hello message. Then they there. And as soon as the boss up, our task is as executed will get there. So, as you can see, we got there on it is here in the something went wrong. Okay? And we're able to do this bites in playing a single catch block, okay? And in case of promise, we had hoped, like edge, block to each and every promise called. Okay. And one more thing I would like to tell you about the think of it. Keep it. Is that the await keyword off course expects the promise. Okay, so in our case, it is returning a promise. So it is working. Fine. OK, so you can apply the orbit keyword on lee to do two things. The 1st 1 is if you're function, is returning a promise which, in our case, it is doing ok. So the display messages returning a promise or your function should be facing function if it is in order turning a promise. Okay, So remember these two cases, Either your function is returning a promise or your function is an amazing function. So let me show you by example. So let me There's declared a function over here quoted as greetings on, let me make this function as a sink. Okay? On it is going to simply there, done, for example. Hey. Okay. So now I can apply the await keyword toe this getting function because it has these in keyboard with it. Okay? And remember, I just told you right now that either the function has student and a promise or it has to be anything function. Okay, so let's just rightto apply the await keyword. So this greeting function okay on, let me simply get the result here and let me even console lobby. So now I'm going to execute this. But before that, let me just simply them comment about this court blocks so that we don't get any sort off better. Remember, this particular promise is executed. Okay, so let me just go be their dominant on on this fight. Says you can see we guard the hey my sexual here, which is printed over here, right? So now let's understand what special difference does the ace in keyword makes to a normal function. So animal you apply is in keyword toe a normal function, and it returns the value than this value is not return as a simple value. Instead, this value is returned as a promise. Okay, so what it will do is it will try to always result this particular value as a promise. And that's the reason why you are able to apply the orbit. Key word on the matter of the fact is, if you are using this hazing function, then you can also simply say great things. I thought. Then you can apply, then over here. Okay, so the reason you can do it is because this is basically resolving as a promise. Implicitly, you are not able to see it. But the Zinke what is doing that? Okay, so let me one show You Okay? So I'm going to simply quickly console log they deserved over here. Okay, Now let me go to their dominant and run this file. So as you can see, we got the value right away. So there is. This was all about these. Think of it. Keyboard on. I hope you were able to understand this on. Thank you so much for watching this video. 4. Spread Operator: Hello. Everyone on in this really of your going to understand what a spirit operators in tax on how can we use it? So basically spread operatives in text allows you go fetch the elements from the variables such as our A string and even the object says Well, so let me show you by example. So first of all, I'll hear create a file called us spirit operator. George is okay. And let's say I haven't had a over here called as everyone. Okay. Which is holding value such as Warren to entry. Okay. No, the way you can make use off spirit operator is by simply saying, let me show you by example, this index for it is triple dot on the your trouble with this away. Okay, so let me to save this. Let's go to the terminal on this particular fight. So I'll say North spirit operator Dajae. So as you can see regard, they weren't 23 Okay, So what this index is doing is it's simply taking out the values from this area and spread it over here. Okay, so it just printed 123 Okay, Now what I want to do is Let's suppose that I have another day called as Const Readyto. We just require toe for five and six. Okay, now let's I want to create Thurday using this forced to always so I can simply say concert a tree equal toe I can spread over the other one. Okay, then I can spread over all the values off the radio, and that's it. That's all I need to do. So let me just console log this as well. Okay, let me simply say this on down this file. So as you can see, I got it. Artery, which holds value such as 1234 which belongs to the 1st 1 Okay, so it is spreading over here, and then we have 456 Okay, which belongs to the secondary. No, If I was not using this spirit syntax than what would have happen is that it is going to simply, um, put this whole array instead off values over here. So this word form on estate. Okay, so let me show you. So as you can see, this is your main today and insert off this. You have this whole array. So this is the everyone on. This is the radio, but that is not what we want, right? It is creating a complex data structure. No. One more important thing about the spread operator is that along with the spreading values , it always make a copy off the sore. So, for example, here, the sources Everyone on here, The sources are there too. So it is not going toe. They're friends this way over here. Okay. It is always going to make a copy. So how it is beneficial for us. So whenever you make a corporate to a new area and if you make changes to the newly than it is not going to reflect on the old one, right? So that's also ended one days off this pretty operator. Now, let me this also show you the example how their friends creates the problem. And it's not like spread operator is mainly for solving the difference problem. Alderdice spreading out values. But it is also creating a copy off those sores. Okay, it is not going to the friends it. So let me show you by example. So I will come in this out, okay? And let's assume that we wanted to keep the other three as the other one. So the one ways to do this, which is simply assigning the everyone podiatry, Okay. And I suppose if I change the area tree on, push some other values such as six over here on, let me simply print both off the area. We're here. Okay, So I'm going toe for India. Where one as well as theory three. Okay, so they're going to save this. Go to the terminal on if I run this particular file. So, as you can see aboard the array, hold the same value. That means the six eyes post toe the other one as well, even though I just pushed her to the rectory. Now, the reason this happened is because this is creating a friends to the array three. Okay, so it is not creating a copy offered. Now, one ways to solve this problem is by using the A one dot slice matter. Okay, So what this will do? Is it instead off for a friend singer? They want to the territory. It is going to make a copy off the everyone to the other three. So let me just around now. So as you can see this time the everyone is holding its original value, which is 123 only. And since we pushed the six value to the other three, it is holding 123 and successful. Okay, so, no, I am going to somebody comment on this line. Okay? And instead of slice matter, I'm going to make you love the spread operator, which is everyone okay on Let me the sport do triple dot over here on GMA. Tried to run this again, and you will see that again. The everyone is holding its original values, and the tree is holding 1236 Okay, so that means this spread operator always makes a copy off the source instead of creating a difference. Okay. Okay. So now that we have understood everything about the raise, now we will understand. How can we work with the object using the spread Syntex. Now I'm going to make it off the same object that we used in the previous video, which was this one. Okay, which is a user object and holding some of the properties. So let me just simply call this as user one, okay? And let's assume that we want to create a user to object. We told the same values, but I just want to change the name from David to John. So let's see, How can we do this? So here I'll say user toe, which is equal to user one. Okay. And I want to change the value as user to dot name equal to John. So let me just console of both of this. So he writes a console log. Use that one, which is user one over here. Okay on. I'm going to console along user toe as well. Okay, Now let me open up a terminal on school. Don't. Over here on. Let me just put on this fight. So now you would see that the user one named property is overrated with the John. Okay. Even though I only abraded the user to object. So the reason this happened is because user one is being created as a reference to the user to object. Okay, It has not been covered, so let's see, How can we copy this? So the one way is to make use off the object, the senator, So I'm going to simply say object, not assign on I'll be is their target object where I want to copy the object. Okay, so their target object is user too. And this source object is the user one. Okay, Now, if I run, leave this fight again. You will see that the original object, which is user one, is holding the same name property with this debit and their target object updated. The name property is John. Okay, Now, let's see. How can we basically do everything using this print operator that we're doing over here? Okay, so the idea is to make simply a user to object, and over it the name properties, John, using the spread operator. So I'm going to come in this out, okay? And here, I'm going to say, const user toe equals to object. So first of all, I'm going to spread away all the properties off the user one Okay on. I want to update the name. Okay, so he rides. His name is John. Okay, on Let's I want to add extra property, which is gender, okay. And I'll call your desk meal. Okay, Now, this name property will be overrated in this user to object because we're spreading the all of this property over here on this name, Robert is already present. Okay, so it will be overrated. And since this gender is a new property which is not present in the user one object so it will be simply I did for the user to object. Okay, so let me just write good on this again. Let's see what result over get. So as you can see, the original object is holding the same values. And the new object has the Jonah's new property. Also, it has the gentle property that we I did over here. OK, so as you can see how easy it is to our makers off this print operator OK on simply had some properties to it on. You can see that even though I know where I did the name property, it is not being overrated. Toe the user. One object because you're this creating a copy of the user. One object, nor did their friends okay on. And you can see instead off these three lanes, it is the court guard converted into just sing aligned right on. In fact, there should have been one more laying for riding the gender over here Okay. So, in fact, the four lines are converted, known to just single line. Okay. So as you can see how easy it is to work with this plate operator and how it basically is the least spread over the values OK from the terrible, such as object. But as well as strings on it is going to create a copy off the source instrument. The difference. Okay, So you guys, this was all about this spread operator on. I hope you were able to understand on Thank you so much for watching this video. 5. Object and Array Destructuring: Hello, everyone. So in this video, we're going to understand what is day structuring on How can we use their de structuring? So districting basically allows you to fetch the properties from the object on values from the into individual variable. So let me show you by example or they mean by that. So here I'll create a file called as they structuring Norges. OK, now, in this file, I'm going to First World declared a user object. Okay, on this user object is going toe hold some of the property such as name as David then we have ages. For example 22 then we have city as so like city on Finally, we have country as USA A OK, so let's say we have the user object now. What we want to do is we want to fat to the name and the country into individual variable. Okay, so the way you would do without the districting is very declaring available over here. So you would say const name equals user Gortney. And you would say const country equals user dark country. Okay, No, let me the same play playing these two variables over here, so I didn't say Name as name. Over here. Look it and the same for the country. Okay, so now let me open up a terminal Onda on this particular fight. So here, I'm going to say Nord the structuring George's. So, as you can see, we got the name is David and the country, as you say. Okay, now let's see. How can we do the same? Using their day structuring. So that told you before that the succeeding allows you to fight city properties from the object. Okay. And here, very now, using the object will also consider the example of theory. But let's first have a look at the object. So first of all, I'm going to commend this out and the way you can Destructor this object is basing Const. Then you have the space of medical lib assists. Then you have to specify the property names that you want to fight from this object. And remember that this property name should match the properties president in the object. So, for example, I want to face the name and the country. Okay, so this is how I would do it, and I'll pass the user object. Okay, So what it will do is it will basically source for the name property in the user object and declared country property in this user object. Okay. And it is going toe create the same to individual variable with those values. OK, so this is not creating object. Okay, this implicating to conserve variable. So let me simply say this And since we have control logging this very well, be sure against get the same dessert. Okay, so here, I'm going to say north this fucking gorgeous so as you can see again regard this individual variable. Ok, so a lot of people get confused, like whether it is an object or something. But no, it is just creating two variables. Okay, This is how our districting works with the object. No, let's understand. How can we deal with the party as well? Okay, so here, first of all, I'm going to declare in Caldas Maya on Let's assume that it is holding lusitans one toe, three in four. Ok, now let's say you want to fetch the force revalue into individual variable. Okay? So we don't restructuring. The way you can do it is blessing const. Food equals toe my array off zero. Then you would say, Const bar, it will do my day off one and finally Const. As equal to my day off. Oh, okay. So let me just spring this individual variable so that you can see properly for us food, okay? And then I'll simply pin the bar as well. And the last one is the jazz. Okay, so let me open up a terminal, okay? And school over here so that you can see properly. So now I'll say, Lord, restructuring Dodgers. Okay, so these were the previous locks, but as you can see Okay, So this is not food. This is full. OK, so as you can see, we have this fool as one bar is too, and the jazz as three. Okay, So this is how you would do it with Alderdice factoring by simply fighting the value from the using the index's. Now, let's see, how can we reduce this number off? Lines on use their destructive. So I'm going to come in this out, okay? And here I am going to say const and I'll declare this square brackets. So remember that in games of object, the structuring they were declaring the Taliban assists, but in case off the restructuring, we have toe declare the square brackets. Okay? And first of all, I'm going to simply positive city. Now, what I want to do is I want to fetch the 1st 2nd and third index value on assigned them into individual variable. So I'm going to stay here simply so full. Then I'm going to hearsay bar and I'm going to say jazz. Okay, so in guess object restructuring it was looking off for these properties in this object. But in case off Ray, what it will do is it will try to fetch the index according to index. So the first valuable point to this, he wrote next, the second value will point to the forced index and the Third Valley were pointing to the second index. Okay on, let me simply say this and again we showed City same result here also. So as you can see regarding forwards one bodies to win the jazz as three. Okay, So you guys, this was all about the restructuring. Okay, So it allows you to basically reducing the more off line for declaring the individual variables from objects or arrays. Okay, so there was. This was all about the restructuring on I hope you were able to understand on Thank you so much for watching this video. 6. What is GraphQL: Hello. Everyone on in this rid of you are going to understand what is graphical on. How does it compare to the rest? E p. A. So graphical is nothing but a query language for your FBI and it gives the client of power tow us exactly what the night. So no declined has more control over the world. A tight is going to receive Now There are two major problems with the graph girls. Souls over the traditional restive via the 1st 1 is the multiple round trips on the 2nd 1 is were fetching or under fetching their data. So let's have a look at the 1st 1 which is multiple round trips. So in the typical rest t p a u usedto have multiple endpoints, let's say for user for task, for post for orders So you had multiple endpoints which returns my tipple data right. But in case off graphical, we just have a single endpoint for example slash graft will. So this endpoint is just required for the first time to connect to the graphical server on dressed. All the things are taken care by the type system which the graphical implements. So the client no longer has to do the multiple round trips to this over to get my tipple data or different kind of data from different endpoints, Right? So let's ah, in the restive baby had slash user and this slash post, for example. Right now, let's say the claim basically warns the user as well as deposed. So for city vilifies, the users on according late will hit again server and get the user related post right. But in case of graft will, As I said, there isn't a single pinpoint on dust off. The things is menaced by the relational type system, using which you can get every data or all related data into a single request. So there's the power off good after all, So the first, it basically allows the client to get exactly what they need. And second, it reduces the multiple round trips to this over which reduces the over fetching or the interfacing. So just for the example exigency, first of all, you basically defined it schema or their type on your graph. Girls over and climbed can have a look at this schema and exactly ask for what it next, right? So, for example, if declined, just want the tingling. That's always going to simply return the tagline. If the client asked for contributors as well, the subway is going to return the contributors as well. So there's the benefit off using the craft fuel or their Este pia on. One more thing I would like to tell you about the graph. Cool is that graphical is just a specification, so you can find this specification information over here. Okay, On a Z, you can see here is the complete specification about the graphical and on the basis off this a specification various different libraries have implemented graphical in various different languages. And if you want to have a look at all sort of implementation, then you can go over here Then, as you can see for this sort of libraries, the graphical implementation is done in this many languages. And since we'll be using the JavaScript, we have various libraries which are implementing the graphical specifications, such as the graphical tears express graphical and as well as the Apollo sober, which we're going to use in our course surrogates. That's it for the brief introduction on the graphical on How does it compare to the traditional resting point. And I hope you were able to understand the basics off the graphical and its purpose. Onda Thanks so much for watching this video. 7. GraphQL Schema Basics: Hello, everyone. And in this video we're going to understand the graphical schema basics. So let's first of all, understand what it's schema. So schema is the core part off any graph girls over and it basically defined water operation can be performed by declines such as the queries mutation at Spectra. So let's enlist in water. This types and holdover defined their relation. So the first and foremost you have these killer types in the craft. Cool. These are the building types prodded by the graft people on these are intended float string bullion and I. D. I. D is a special kind of skill er type which the graft will uses for cashing on. It is usually used with the feels which are unique. Such Assaidi on this idea is also serialized as a string. That means whether if you posit a number or this string on the server, it is ultimately going to be treated as a string. Next we have the object tapes, so the object it contains group of fields where each feel either is old toe a scaler type or it maps to another object types. So, as you can see, it is the example, where we have object type is user, so it has feel so this I'd email. It is, ERM in as a scaler type, but where this address is on pointing toe another object type. So that's how you define the relation in the schema using their types. Next, we have root level types, so this basically represent the entry point into the graft. Will a P I. That means if you want to do anything with the graphical sour, such as fetching the data or updating the down the graphical, it's over. Then unit don't write with this root level types. So these are basically query, mutation and subscription, and we're going to have a look at this one by one. So let's first of all, have a look at the query type. So credit type is used for fetching the data, and it is a grilling toe the get a p a. That we have intrest. But this is just an anthology. This doesn't mean that the query type in graphical is off type, actually, typically eight. Instead, let me tell you that every AP request in graphical is off post type extra to propose, stable, right, so don't get confused with the acceptable type. It is Justin analogy. Next, we have the mutation time on mutation type are generally used for mutating the data on this over, such as adding something relating something or updating some off the data. So that's where you basically use the mutation type. And again, all AP request to the mutation will be again off post type on, like what we have in the rest api of its airport, Post pass or daily. We only have post type over here in the graft will next. We also have one more root level type, which is subscription. So subscription are basically used for are listening to events that are emitted by this over. So this subscription forms are full duplex bi directional communication from client to sour on. It basically implements the Web soccer behind the scenes and if you are aware with the Web sockets than it is simply the same. Next, I want to tell you a very important difference between the query and the mutation. So remember that the queries are executed simultaneously. That is mutation are executed sequentially. All right, so why did his need for mutation to execute sequentially, not simultaneously. So first of all, let's discuss about the query. If query execute simultaneously, that won't be any problem on the server side. Right. For example, if you simultaneously asked for the list off user or the list off post or list off us simultaneously, that's not a problem, obviously. But if the mutation execute simultaneously, then it might create some problem in some off the scenarios. So let's say you fired two mutation at the same time, and let's assume that they execute simultaneously. So, for example, the first mutation is logging, and the second mutation is add Tusk. And now let's assume that this ad task mutation depends on the user authentication state. That means this mutation can only run if the user is locked in. So if both off this mutation done simultaneously, then there is a possibility that the second mutation, which is at task run before the forced mutation, is even completed. So your second mutation might feel right, so there are a number off scenarios. This is just one of the examples in our use their toe have taken to make you understand that why the mutation execute sequentially and why the query are executed simultaneously. Since the mutation basically manipulate our mutate, the down the suicide it is very important toe have a proper sequence in which the data is being mutated. Right hands the invitational, generally executed sequentially instead of the graphic. You'll now let's have a look at day input type. So input type basically allows you toe except object as an argument for queries and mutation. So, as again see, here is the example. The first example is without being put Tape on. The 2nd 1 is with the input type. Now, in the first example, we have this create past mutation, which is using in the name completed field on the user. I d feel as an argument that you need to pass toe this particular mutation toe work on. Now let's suppose that this number off argument grows to the count off 15 or 20 arguments. So in that case, it is better to have all of the argument in a single object instead off defining all those 2050 arguments over here. So for that, you can make use of the input type, as you can see here we have two mutation create task and abject us, which are expecting task. Input on this is basically a input type which is holding all the feels right. So this particular mutation is basically expecting the object which is defined over here as an input type. Now, another advantage off defining in port type is that you can share it across multiple mutation as we have done it over here on the multiple queries as well. But you should share the import type very carefully. There was. It will make it very difficult for your graph girl scheme, Otto skill. So let's consider this example where we're using this task in port type this create task mutation on. We're using the same type in the object. Ask as well. So for they create us or destructively fine. But for the update task, it is not necessary that the user will pass all the three feels user. My NATO simply update the name or the convicted staters. But all of this feels are basically required in the clear task mutation. Right? So it's not a good idea because you're objectors won't work fine. It will only work when users will update both off. This failed. So in such cases, you should create separate input type for both of this mutation on, you should carefully share it across various mutation enquiries. Now let's talk about the customs killer types. So, apart from building scaler types, you can't define your own custom scaler type, which we're going to do in the upcoming videos. So this is to fulfill your custom needs. Next, let's talk about the interface type so interface that basically allows you to define the abstract type. So although this cannot be used directly in your schema, but you can use it as a base for defining your other types. Now let's have a look at the union tape. The unit basically points toe one or more other object types, and you can use this union in your schema, which can return one or more object types. Next, we have the norm. Tapes on these are basically enumeration, so this basically defines the specific set off values that you want to allow on. You can be fined the sum type 15 keyword, as you can see on the screen on. Then you can use it in sort off your schema as an argument, or desert and value as Reagan see on the screen. So what is this world? The basic graphical skimmer types that I wanted to discuss with you in this video. So that is, that's it for this particular video. And I hope you were able to follow along. And thank you so much for watching this video. 8. GraphQL API Overview: Hello, everyone on in this rodeo. I just wanted to give you a brief information about the graphic really played that we're going to build. So we're going to build the AP for managing the task so user can create task. Update US daily task and as well is list all the task. So as you can see, we have divided this AP. I asked for their purpose. So we have some of the queries. We have some off the mutation on. We also have the subscription as well. So these are the a p A that we're going to build on as every application requires the authentication and alteration, so will implement the logging. And this an A p p i onda. We will protect the other repay, such as Tusk Update US Daily Task and also test list Casbah ideas. Where is the user variety? So only the logged in user or the authenticated user can access this A p A's and also every application needs the detonation as well. So we're going to implement a pagination on the task list AP I and we're going to implement different presentations. Credit is such as off certain limit pagination as ballistic car service pagination, and we're going to compare them in depth in the opponent videos on. We're going to implement the most performance one, and we're also going to implement the subscription as well, which is going to set up a real time communication between declined in the server and as soon as the user sense of the clan will be notified with the user details that just signed up. Apart from this will also see how can you optimize your graphical server so that you can return faster results of the clank. So will implement library such as the borders, which allows you to implement batting and cashing for your day Texas layer and along the way you are going to learn various concepts of the graft will. And overall, you're going to cover it in every corner, which will make you feel confident with the graphic You'il and you guys. That's it for the brief information on the way that we're going to obey and I'll see you in my next video 9. Setup GraphQL Server: Hello, Everyone on in this. Really? If you're going to set up the graphical Apollo server So the first thing that I would always to create or directory over here called as graphic you will I find Apollo? Hi, friend. Maybe I on inside of this. First of all, I'll initialized the packaged Georgeson filed using the NPM innit? Command on. I'm going to use the hyphen by flag to set the defaults. All right. And now I'm going to simply install couple of packages such as Express also going to install Apollo Server iPhone Express Liberty, which is a middleware celebrity for the express framework. Next, Also going to install the course packets for handling cross or is in the quest Onda Also going toe have the daughter envy package for hell Indian woman. Very well. So going to simply hit. Enter on. I'll get back to you as soon as it is done. So as you can see, the installation is done. Now, I'll simply open up the court in the bs cord. On the first thing that I will go here is to create off oil called us or our door, Jess, where we will set up our server. And instead of the packages and file, I'll specify the main file as Sarwar George's. Instead off the default index Georges, that was created because we used the default to a lose while initializing the Pakis Dodgson file using the hyphen wife flag. So first thing that I will do here is to require the express. Then I'll also require the Apollo Sarwer from the Apollo Sarwar Express on. Basically, this is the structuring so going to get the possible from here, then I'll also require the course for handling the cross or is in the quest. Andi, I'll also require the dot envy for handling the environment variable. So here, going to simply say, require Doherty and be all right now, the first thing that I will do is tow set up the environment variables. So here, going to simply say, Dottie envy, not conflict. Know what this will do is dot in we don't convict will basically look for our daughter and we filed in your road projects. So let's create it over here door PNV, and it is going to pick up all the variables. Defend over here on it is going to put everything in sort of the process dirty. And we thought that particular variable. All right, so here, first of all, I'm going to define our moment. Variable called the sport, and I decided to 3001. All right, so that's the in women available configuration. Now let's set up the express apso window. Simply say, const tap equals express. And I'm also going to set up the body parts of middle. Well, so here I'll say middleware. I'm going to simply say up Don't use This is uplevel middleware Onda hands using the use method on the app Instance. So here, when the Simples Express Dark Jason All right. No, You basically create the port that we will use Insert off the abduct. Listen, mattered to start this herbal on this particular port. So here, going to festival Fetchit from the environment. Variable on If the port is not fun in sort of the environment. Very well. Going to make you suffer The full port called us 3000. Okay, on in sort of the environment variable. We have 2001 and here going to someplace abduct. Listen on going to pass deport on in the callback function going to simply say console, not log on here. Going to simply say, sir were listening on board on going to specify deport Over here. So here, Windows implicit board. Alright on. Remember that I'm using the back takes over here. These are not just normal strings. These are back takes. All right, So I think we're good to go just for the testing. The part going to create a route part which is slash on Dhere going toe to save the request response object and the next function inside of the call back and here going to simply said response, start saying and going to send the message as Hello, All right, SOFA leaders looks good on Let's go to the terminal on Let's Start December So here L simplicity Nord said Ward RJ's. So as against your sales that were listening on Port 3001 let's go to deport 3001 and let's see, what do we get? So as you can see, if you get the messages had looked on, what I'll do is I'll set up the NPM script to start this over on aisle. Also set up a library called as Norman so that I don't have to restart this or what again, if I make any changes. All right. So, for example, if I say hello, Hi, then the changes are not reflected on the Flay. So what I have to do is our booty Start this road again and again to see those changes, as you can see. So I'll set up a library called as Norman so that we don't have to start this over again. So let me simply do it. So here, as an install high Fundy for their dependency and I'll specify did not one package. So as you can see, the installation is done. So here in the package stock. Jason, I'm going to create some script. So first of all, you create this start script on here, going to simply say, Nord server Georges, which you will usually using protection more but further development more than going to implicate another script. Corliss, Death on here. Going to simplicity, Norman said, were dark days. All right on now, what you can do is you can simply say and b m under to start this ever basically doing that daft script and everything will work for him all right now, if you make any changes than those will be reflected on the fly, you don't have to. They start this over again and again. All right now, before setting up the Apollo's over, I would like to also set up the God's on our application because since we're building the E p A, and you can be accessed by multiple domains, so we need to set up the cars because there's how the browser policy works. Otherwise, if you don't have the course enabled on your rapier, and if multiple domains are accessing your Abia, then you might get the cross origin error that you usually get on the browser. So let's enable the course. So here, going to simply enable the course so gonna say, I've got use and all you have to do is simply part of the course as a middleware over here . All right, so that's it. Now let's set up the Apollo Sorour Middlebury. So what I'm gonna do is here going to simply say, const. Apollo Sorrow on going to create a new instance off the Apollo sober. Now, insert off this, you can parse videos, conflagration, but as off No, I'm going to pass their type definition, and I'm also going to pass. It is all worse. Instead of their type definition, you basically defined the schema using this game or definition language. And instead of the result, would you define how do you basically get their data for their particular schema? So for defining the schema, I'm going to make use off the Deka well from the Apollo Silver Express, which is called us temporarily total tack for defining the skimmer definition language inside of this string. So here, going to someplace that const type deaths equal ridicule on, then you space where the back ticks and in sort of this you basically defined the schema. All right on, for the result would I'm going to simply as off no static to empty object. Right? So let me see if this on now, what I'll do is here. I'm going to set up the Apollo several middle way. So here, going to simply say, Apollo, sir, where dot Apply middleware on. Instead of this, I'm going to pass the express app instance and then you can pass the part on which you want to make your craft. Girls are work to listen toe here. I'll specified the graft US department, but you can name it whatever you want on it. Last, basically, add another console log message for the graphical in point. So if you're going to some place a graphic, you'll end point on going to get the graphical part from the Apollo server. Dark graphical part. That's it. So I think our graph conservatives set up on the only thing that is remaining is toe are defined the route credit type, because if you don't define it than the graphical Sarwer will throw at it on will not run. So as you can see under community Spring summer, so here, going toe defined the road very type. So when I said type query on inside off this, I'm going to just define a single field called as greetings on this one simply did on the string. So going to spit out this string scaler type over here. So let me say this large school, but they're terrible on. As you can see, this hardware started on the graphical and point is slash graft world, So let's go to the browser. The fresh as you can see here we have the basic message from the express road. And if I go to the slash graphical wrote where our craft fuels our God is listening, then as you can see, we are presented with the graphical playground. It's a tool for testing. Declare off Libya. So here you contest everything. Your query mutation as well is the subscription on We're going tohave a brief or view about this particular tool in the next video. But as off now, since we have just wrote a single query, which is grating, let me just try to show you How does it look like and how to basically equity instead of the graph Cool playground. So for stole, you have to space where the name of the operation that you're performing so it can be pretty motivational subscription. So going to specify the query over here? Then I told the name of the credit, which is creating, and if you simply click on display Burton, then you will get the response from the server Now, since art is always empty is off now because we haven't wrote any logic for resolving this particular query hands we're getting now, but we're going toe walk on the queries and result or more in the upcoming videos. But in this video, I just wantedto get do I set up with the Apollo, said word on. That's it for this particular video, and I hope you were able to follow along and thank you so much for watching this video. 10. GraphQL Playground Overview: Hello, everyone on in this world of you're going tohave we'll look at the graph. You'll playground overview So basically, it's a tool for testing your MPs on here. You basically write queries on here. You will get the dessert that is signed by this over. Now here in their dogs option, you will see these self documented graphical schema. So if you basically condition it will exactly tell you what kind off. What is that you can perform on in the opponent does. We're going to add the mutation and subscription. So I love those will appear over here along with what kind of data they're expecting on what I what kind of data they're going to written. Everything is self documented over here on the basis off this schema that we defined on the graphical using their types so you can find every information about your graphic really pay Over here, anyone can have a look like what are the fields available? What are the Curries available? What are the mutations as well is the subscription and accordingly they can carry the graphical ap A All right on. If you basically go to deserting than here, you can do bunch of configurations such as setting deformed foreign size at Spectra. But one important thing over here is the schema polling. So what is a scheme? Appalling Will do is it will try to hit your Sarwer every two seconds. So whatever in total you have defined over here it is going to hurt every two seconds and it is going to automatically update the scheme over here your own have toe the fresh debate on you can even see this I can over here, which is beeping as you can see. So it is saying polling schema. That means every two second it is trying to hurt this award on Let me one show you by going putting a cook tab. Then, as you can see every two seconds, this request is being hit with the server to get the latest schema. But I personally like to disable it. So what you can do is if you don't want this behavior, then you can go to the settings on Dhere in this scheme are pulling, not enable you can set it to falls. All right, so here are basically second toe falls on. That's all you need to click on Save setting and that's it. No, if I basically go to the night walked up the residency Now there is no ah frequent a hit that the graphical playground is performing on. That beeping Aiken is also going now, you also have option off creating multiple times over here so you can get as many times as you want. You can basically group multiple e p s. They need steps so that you have probable segregation for tasting a lot off a PS altogether on. But you also have this option called us prettify. So, for example, if you want toe ah, structure or intent your query properly or the mutation. So, for example, if my intonation is wrong, I can simply click on this prettify Burton, and it will properly intent my credit. You can also click on this history button so you will get all sort off a p a that you have performed on. You can access any off them. For example, if I click on this and I can simply say use and it is going to basically use it right on, it has basically open new type for the that particular a p a on. If you have a look at the bottom left corner, then as you can see, you can said the extra tippy heard us over here on. You can also said the query variables over here. So we're going to see this in the upcoming videos when we actually create daiquiris or the mutation where we need to side the very variables or the expected Behead us so. But just wanted to give you a brief information regarding the same on you guys. That's it for this particular video on I hope you were able to follow along on. Thank you so much for watching this video. 11. GraphQL Resolvers and Type Modifier: Hello, everyone on in this video, we're going to have a look at their is all words on the type Modifier says. Well, so let's first of all, have a look at the result wars. So it's off now. We're getting no for this particular Kredi because we haven't defined it is over yet. So let's do it now. So I will basically go to the court base and here, first of all, you have to define forward type you're writing. The result were So we're writing this fork ready, so you have to exactly define the query over here. Then you have to specified equerry name. So in artistic worry, name is Greetings on. This is going to be a function which is going to return something on that will be sent to the claim. And it is. All order saves a bunch off argument, which we're going to see in the upcoming videos. But as of now, I just wanted to show you how did is, although works. So here I am going to simply return a string. Korda's Hello. Let me see if this let's go to the browser and if I hit, enter now then, as you can see the hello is basically returned, right? So your result wars are responsible for providing the data for your quickie and mutation. Now let's understand what our type modifier, So one off the type modifier is nominal on. You're going to use thes quite frequently, so it is diluted with exclamation mark, and it basically defines whether that particular type can be no or not. So let me show you by example. So let's go to the initial state where we were not having any sort off result work. For the greetings, Let's go to the browser hit enter. So as you can see the great things is that returned as no. But if you want to specify that the grating can ever be no on this, artwork will never return denial value for the greetings. What you can do is you can add a type modifier over here called is not available. So if you had this non a level type modifier now, if I go to the browser and hit, then as you can see the graph, we'll start where validation will throw this error and the message is, cannot return all for non a level field. Very dark. Greetings. So this is how basically you can use the modifiers on you can use one more modified, which is toe define our type as a list off items. So, for example, if I basically defined it like this by adding the square bracket, this means this particular type is off list on what I can do is here in the result where I can return the list of items such as a low inside off the list. So let me see this. Let's go to the browser. And if I hit this now, then, as you can see inside of theory, we have this. Hello on. Let me add more items over here. All right, let me go to the browser on simply hit this. As you can see, we have multiple items over here on you can add the modifier, which is noncallable modifier inside off the list modifier as well. So for example, here also, I can say non a level modifier. So if I tried toe written any null item, then it will for the other. Because here what we're seeing is not only the list will be nominal, but all of the item insert off This list is also nominal level. So let's go to the browser. If I hit this, then as against eight seeds cannot additional for known arable field corridor Greetings. And if I remove this null free from here, save this. Go to the browser hit Enter the next concert works fine on If I basically remove this null from the list and save this on if I basically did on the Nile from here on seeing this again, then it is going toe work. Fine. Because what we have said is the list can be null, but every item insert off that particular list cannot be no. So this is how you can make it off the normal level type modifier, toe defined how your type basically behaves. So it is. That's it for the these all words and the type modifier on. I hope you were able to follow along and thank you so much for watching this video 12. User and Task Schema/TypeDefs: Hello, everyone. So before defending daiquiris and mutation for the user and the task let's first before defined the object types for the task and the user. We need to define the object type because user in Task in Norway scaler three user will have a much more complex object, so we need to define the type for the same. So the very relationship will work between the user and the task is that users will have one or more test. There is one task will be associating toe a single user so user will have one to many relationship with task. But task will have many to one relationship with the user. So now I'm going to declare the object type for the user. So gonna say type user on it will have feel such Assaidi, which will be off type ideas killer type and it will be nominal. Next, we can also have the name for the user which will be off tripe noncallable string on. We will also have the email associated with user on again. It will be off noncallable string and has asserted the user can have one or more task. So here we will have the task failed on the user object type, which will point to one or more task object. So here I can have the noncallable task insert off the list. But the list itself can be no, because there is a fair chance that user doesn't have any task associated with. But if it does then insured nor Minal. So that's what this particular thing represent. Next alleged declared the task as well. So here, going to simply declare object type for their task task will again have the i D felt, which will be off the scaler type. It will also have the task name eso going to simply at the non a level string. Next will also have a Boolean variable longer task, which is called US Completed on again, it will be off type non label bullion and as a sad task, has many to one relationship with the user. So that means anyone task can only have one user associated with it. So here are declared the user on this will be off type user. I'm not putting this as our list because, as I said, it is many to one relationship on. This is also non a level. So I think our scheme is ready on in the next video, we are going toe create daiquiris and there is all worst using which the client can get data related to the user and the task. So I hope you're able to follow along for this particular video. And thank you so much for watching this video. 13. Task List Query Resolver: Hello, everyone. So in this video you're going to implement the list task query so users can basically asked for the list off us. But first of all, we need to have the data. So it's off. No, I'm going to use the Dominator on later. Down the line, we're going to replace their imitator with the Mongo DB database. So here, first of all, I'll create a folder card as constant on. Instead of this, I'll have a file called US Index Torches on just for their demonstration. I have prepared the list off task and the list of users, as you can see over here. So for the list off task we have failed, such as idea name completed bullion status on the use ready on. We have the list off users where we have feel such Assaidi name and email on it. Task has a user. I d associated to it. So it basically points which user the stars who belongs to. So let's use this dummy data to create the task list. Worry. So let's go to this. Our door chess on here. I'm going to add another credit card as dust on this will be off type list off task on every item in sort of the list will be known a level. So I led the mortified over here on this Looks good. We can get the whole task has no, that's not a problem because there is a possibility on a fair chance that user doesn't have any task associated to it. So in that case, we will return. All otherwise will return the task that is associated to the user. So now we have this Eskimo defined Let's defined. It is also for the same. So here in dick, ready, I'm going to ride. It is always so here are basically defined the name off Dick ready for which I want to write the result work on it is going to get function on as off Now I'm going to simply it on their task on I'll get this starts from the constant. So here, going to simply say const on would like to require it from the Constraints folder so I can get it from the constants. So he really basically say, does on. As you can see, this task will be available over here on it will return to the clinic. So let's test it now. Let me see of this. Let's go to the browser and they're fresh on. First of all, you will see that in turn of the dogs Now we have New Korea. Did which is task. And if you click on this than you will exactly see awards the structure for their task on what are the feels that you can expect from this artwork to written? So here's what I do is instead of greetings, I would like to now hit the task Ready. So what I'm gonna do is you can basically also press controlled space so it will give you suggestions like water credit you can trigger. So you like to trigger the task. And then you have to specify the fields that you want from this over. So let's say we want the i. D. We also want the name on. We also want the completed. So if I hit, enter then. As you can see, all of this feels are basically written on it. For example, if I don't need this completed status, I can simply remove this on hit enter. Then, as you can see this, I've got only returns to feels the idea in the name. So whatever data there to written from the result war graphical will exactly pick does feel that you have defined insert off your type. So here from the constants we are returning the fields such as the idea name completed so the graphical will automatically pick up this field on field, return it to decline. If you send any extra fees than draft, will will not entertain those feel because those are not be finding this schema. So you can only work with those pills which are defining the scheme out, no matter what there is always returns. Now, if you're wondering, how can we get the user detail right? Because in the scheme of we have defined that for any task, there can be a user which is associated to it. But as of now, we have associated the user. Do another object type of its contains I D name email in the task. So the way you can get the user information on the task object is by simply specifying the user feel over here. Then you also have to specify the field that you want from the user, so again here. Also, if you place control, enter the nets again. See, these are difficult available on the user type. So we have a D name email. So you can basically asked for I d name on the email right now. If you have a look at the data properly, then we don't have the user information on the task object. The user information is deciding in some other way on in case off database, it will be in some other entities, right? So what we have just stored here is the user idea itself. But what we're creating here is the idea. Also name also email also. But those are not president over here. So there is no way that the graph will confess the data from this result war because all we're returning to the graphic UAL is the i d name completed and the user ready. But instead of the scheme of your allowing the user to fetch all the fields related to the user object type, which is a separate object type, So in that case, what you can do is you can either get the user information over here itself. Andi, you can basically provide the object in the form of, for example, like me to show you So Currently we are providing the object like this in the result work. This is what we are returning. All right, so let me show you. But instead, what you can do is you can treat on another object like this, and then you can have ah, user information fields such as name on email and so on. So this way are the graphical. So what will know what information to give back to the user. But this is not an efficient solution because party user doesn't even ask for the user feel . What he will do is you will end up fighting the explain Formacion from another entity. Right? So that's an extra information that you are getting which is not even required. So how can you overcome this situation? You can simply work on this situation by writing different level result war which we're going to see in the next video. So I'm going to remove this comment on we're going to write the free level result work in the next video on that field result were will only going to run then the user filled or user type is requested by the user. Otherwise it is not going to run. So we will not fetch more information from various entities. We will only fetch those that up. It is required by the user. Ondas off now. If I hit this, then of course it is going to get another because we are not returning the leisure information, right, Because there is no past or user associated we always pretending is the user i d so essentially the user for listen. All right, so in the next video, we're going to handle the free level results on that's it for this particular video on. I hope you were able to follow along and thank you so much for watching this video. 14. Field Level Resolver : Hello, everyone. So in this video, we're going to write the field level results for the user so that we can get the information over here in the task. Very. So let's do it now. So let's go to the court. Weighs just like you defined the result wars for the Kredi instead of the query object if you want. Oh, right. There is a word for a field. You have to specify it. Insert off the object type in which this present. So since we are quitting, the task is off. Now, on the user this president instead of the task Arctic type. So here I am going to specify the task object type on. Inside of this, I will specify the field for which I want to result or value. So we want to result for the user. So let me specify it over here and the field level result, but also has the same argument as all other is always so it will. No, we haven't discussed about what are the arguments? They're not available inside off the result wars. So let me just show you. So as you can see on the screen, there are basically four arguments they're not available in sort of, the result will function. The 1st 1 is called US route or a parent on it basically contains the desert from the previous result filled. The next one is the art on it contains the arguments. Object. So it basically holds all the argument field that you passed to the query or mutation on. Does that available in sort of the result would function. Next. We have the context. Eso We're going to learn about the context concept in the upcoming videos. But just for letting you know that context is just an object which is shared by all the result wars, so you can share information such as the art state our digital orders on. We're going to understand what are DHL orders in the upcoming videos so you can share all the information which you commonly need across multiple is always so you can do it using the context and the last one is the result. Warren, for object on it, contains the information like, what are the fields that are being created by the blind? So you guys, these are the four arguments they're not available instead of the result or function, and I'm going to use the parent argument is off now. So going to specify different over here on this parent object will basically hold the result value for the previous field or the parent fail. So for different feel. For a user that you defined over here is the task object itself. So what this parent object will hold is the individual task object. So now what you can do is you can grab the use ready from that object and grab the user information from the users on return. The user object so that the client can view it. So let me show you how is their done. So here, going to first of all require the user constant. So you're going to simply say, users on here. What else simply do is I'll say users don't fine on again. I basically get individual user in 80 tradition, and I only want to written that user whose idea is equivalent to the parent dot use ready Now. Hopefully, this makes sense on what you can do is to make it even shorter. You can restructure the use ready from the parent object so you can be structured it like this and you can use this use already over here. So let me see this on. Let's go to the browser and see what results do we get. So if I hit this now, then as you can see, I'm able to get the user information. If I basically asked for the name, I can get the user name is well, and if I ask for the email, then I'll get the Malays. Well, so this is how you can write the field level result work. Now, there are some of the things that I want to talk about. Different level results, such as their order off execution on how the graphical prioritized the free level result work or the credit is always so let me show you. So just to explain you, this expense off execution first, What I'm gonna do is I'm going to simply add a console log over here on going to specify the task over here on going to simply rate on their task. And I also read Dickens a log over here as well. So let me simply return this thing on Dhere going to simply had the console log as simply user, I d on going to print the use. Ready. So now you can probably see that inward sequence the query result weapons as compared to the field level results. So let me see if this we have the criminal over here. Let me simply here, this FBI, and let's see word results you get So as you can see, the force lock that we get is for the task list. Basically. So this is what we have printed over here. That means that Africa will not move to a different level. Dissolve word until and unless the data is available from the query result, would next word graphical basically do is it basically takes each and every item and checks . If there is a fear level result war that this president over there, if they feel level result what is found, then it is going to replace the existing item. The different levels is always so. This means that the free level result war is given higher priority than the actual result from the credit is always so let me assure you by example, So currently we are getting the task name as work. Then we're getting the shopping. Then we are getting the gym. So this is interrogator that is being returned by the this all war itself. We don't have any sort off free level result were for the task name, Right? But let me just add it over here. So going to simply add the name over here on going to simply return a static name for the last name? Basically. So here I'll simply say test task. So let me see if this No If I heard the A b I let's see what happens then. As you can see, for every task the name is test, ask for the first. Also second, also for the third item also, And for the fourth item also. And if you have a look at the console, then there is all over actually returned different last name. But since graphical looks for each field level result war, it basically found all dead. Okay, so the name has a free level result war. So it is going to grab that and it is going toe over the value that is being returned by the where it is always. So I hope it makes sense now. So we have basically learned two things over here for sun is this expense off execution between the query resolver what is the field level resort? Well, and the second thing we have learned is that the free level result word is given higher priority as compared to the query level results. So I hope that makes sense on I'm going to remove this name free level. There's always off now. I'm not going to use it. So going to simply say of these, let's go to the browser hit Enter then. As you can see, it works fine on. Now. If I basically remove this user field, you will see that this free level result war will not even execute. So we won't forget the extra data from other entities collection or maybe some static data source, just like we're having. So just for those Sekoff showing you let me say this to the time so that the previous logs are gone and now we have simply dish to cancel logs. So now if I basically remove this field and if I hit enter, then let's go to the console. Then, as you can see now, we only get the logs from the credit is all work, which is over here. We do not get any logs from the free level result war. Because we didn't even ask for this field over here in the credit itself. So I hope this makes sense to you. Ah, Now I hope you're able to understand the field level result war and its purpose on Thank you so much for watching this video. 15. Get Task By Id Query: Hello, everyone. So now we have defined the list off task query. Now let's defend another career wearing user. Can fat ah, particular task with the help of I D. So I basically go to the court base on here, going toe, declare another query called us Task. And here, I suspect, declined to send the ideas and argument toe this Kredi. So this is how you can be fined. The argument on the argument name is I D on it is off type I D, and I'll keep it as noncallable on it is going to return a single task. So let's define the result were for the same. So here I'll basically go. We're here in the query object on here. I'll basically defined the task on it is going to be a function. And here we need to send the specific task on the basis off I D. On. As I said that the idea will be passed in the argument so you can get that idea in the art parameter. So as you know that the first argument, this parent object, so I'm not going to use it that's off now. So going to simply keep protest cities and the second object is Are so basically so here I can simply say task I don't find and I'll get into usual task in a generation on here. I would like to return those task hose I d is equivalent to art daughter I d on dhere Also , I can be structured the i d from the art. So here I can simply say Heidi and I would like to simply use this particular argument over here. So now let me see this on. Let's go to the browser and test. So now you contest this particular Kredi in this same query, all you're gonna hit this separate Korea itself. So we're going to hit the separate query on Remember that if you want to run multiple operations such a square imitation or subscription in the same place, then you need to name those in diesel operation that it was It will throw the other. So let me just even show you say five, for example, tried to hit the task. And if I specify the idea as one Onda, let me try to grab the field such as the I d on Wharton. Second get I can get the name. I can also get the completed status. Now if I hit this than as agency it says this anonymous operation must be the only defined operation. That means you can only run one anonymous operation. So let's name them. So for this first operation, I limit as get all dusk and I leaned the second operation as get task by i d. And simply going to prettify this on now If I try to run this, then as you can see my second task but on exactly fine. And if you're wondering, how does the second task rent? So if you basically are simply hit control plus enter insert off for particular operation than that Padilla operation is going to execute. But if you want o r un explicitly by clicking on this play button, then you have to choose of its operation Should you run because since you have defined multiple operation over here, so you need to basically chose it so I can choose this one also. And I can choose this one also. Or in short, what I can do is I can move from this operation. We just get us piety over here and any very instead of this particular scope off this operation. If I hit enter, then that particular operation is going to execute. And if I come over here as you can see, my car studies over here in the get tasked by idea operation scope. And if I could enter over here than this particular operation is going to run. So as you can see, they get asked by it is working perfectly fine. And let's try this for the other ideas. Well, as you can see, I'm getting the specific our task by the i. D. And as we discussed in the previous video, is that the ideas? A special scaler type which is always serialised as a string. That means even if you pause in number, tow this popularity, it will be credited as a string on the back end. So as you can see, we guard the desert on. If this was not being treated as a string through the I call and check would have field over here and let me one show you by identical. So lock on the back and so that you can see this idea is serialized as a string on. It is not frittered as a number. So here I'll basically simplifies to fall. Move this thing over here on going to simply it on this on here, I'll add the console log as simply type off on going to specify the I D. On. Let me see this. Let's score but the browser and test like me open up a terminal lesbian. So if I basically had this now let's see what do regard as you can see the other day saving string even though we passed the number, that means the I D type is serialized as a string. So I guess that's it for this particular equity on I hope you were able to follow along and thank you so much for watching this video. 16. Get Users List and Get User By Id Query: hello driven. So in this video, we're going to add the query, forgetting the list off users on also getting the user by Daddy. So here in the chorus section, I'm going to add another query. Korda's user on It is going to read on our list off user, and each user, instead of the list will be noncallable on. I'll add another curry forgetting the user by 80. So I'll expect the ideas an argument over a hill on again. This argument will be noncallable on it is going tobe a simulated on the single user. So let's right there is always one for the list off user, so I just basically go away here on going toe at the user's resolver on Dhere, going to simply return the users on forgetting in beautiful user I'm going to simply defined are visible for the same. So the first argument is the parent object and start off, there is a lot of function. So since you are not using, the parent is off now going to someplace basically the underscore field. This means that we're not using this argument on here in the hours I can be structure the I D on What will simply do is I can simply say users don't fine on in educational. Get single user on here. I can simply say user daughter, I d equals to the idea that this past as an argument, so we have the result or function and ready. But if you have a look at the user schema, you can see that the client can also ask for the list off Tusk that is associated with this user. So we need to write the free level results or for the same. So here are basically festival at the object type. Insert off its We want to add the field result well, so the object type is user and they feel is tusk. So if I said what I declare thee, use that object eight. And instead of this, I would like to have the task field results and again, it's a function on. We do have access to the parent object over here, so I'm going to the structure. The use ready from here in the parent object on going to simply say task don't find. And here in education, I can simply say Nanto stars who's used already is equivalent to the I did that disposed over here. So let me see if this now on, we can test this query. Let's go to the browser on Refresh the app on. If we basically go to their dogs, then you will see that now we have more queries over here for the user. As you can see, we have the list off user's query and a single user query as well. So what I'm gonna do is I'm going to test the user trickery in another tab so that we can quickly switch back and forth on. We have proper segregation between multiple MPs on. Let me call this particular type as escapee and let me call this particular type as use Arabia and you can name it whatever you want. It's not required. So here, first of all, I'm going to execute the query to get the list of the user. So let me name the Koreas. Well, so once I get a call, use us on Dhere. I can simply ask for the users on this. What is the field is concerned. I can ask for the i d. I can ask for the name and let me hit. Enter then. As you can see, I have access to all the users. And if I basically asked for all the US, let's see, what do we get? So if I basically asked for the name of the task on whether it is completed or not, let me a tented. So it's off now it says. Expected it rebel, but did not find one for the feel user task. So we're getting this other because we have defined the task as a list of item. But what we are returning over here is the object this find my third will basically it on an object as soon as it fulfills this condition. So instead of financial aid to use different remitted over here, which is going to written on new array which will content object which will fulfill this particular conditions. So let me say this. Let's go to the browser and if I hit this again then as you can see, it works totally fine. So we have this user and we have the task as well, right? And let's test another equity where we basically try to fetch a single user. So So you're going to simply name the operation as get user by 80. And here I can ask for the single user on. Let me pause the user ideas, for example, one on for So I would like to fetch the user information such as in the name and the email . And if I hit enter. So it says use that is not defined. So let's just go to the court of SNC watched problem. So here it is, basically saying over here. Okay, so we need to simply name it as user and straight off users. So let me see if this let's go to the browser on hate this again then, as you can see, it totally works. If I ask for the second user, then I get the detail of the second user. I can even ask for the ideas. Well, as you can see, I can ask what the card user information as well on the 14th that information as well. And here also I can ask for the task information that are associated with this user. So let's say, for example, if I ask for the last name on for the i d. Let me enter the Nez agency. I get all the tasks. We just associate it with this particular user circuits. That's it. Forget all user on Get a single user by the i d. Equity on. I hope you're able to follow along. And thank you so much for watching this video. 17. Create Task Mutation: Hello, everyone So far we were implementing. The career is only now it's time to implement the mutation as well. On in this video, we're going to implement the create task mutation. So for creating the mutation, you have to declare a root level type called us mutation and insert off that you convey silly the clear your imitation. So here I'll basically create a mutation called as create task so that users can add task into the existing list. Off task on for the arguments I'm going to expect the object as an argument. So for the name of the argument, I'll keep it as input and ill defined this particular argument in a bit. But for the naming, I'll call it as create task. Input on it will be known. A level on this mutation is also going to return the object type off task. Now let's defined this producer input over here, So going to simply say, input on bill aimed input as create task input on. We will define videos field that we want for this create ask mutation. So here, going to simply defined the field, such as name on it will be no no label String Next ill defined the completed, which will be known a level 1,000,000,000 on I'll also define the use already on. This will be non a level already. So that's all I need for defining the schema. Now let's defined it is all work for this magician. So let's go over here. So now since we have implemented the mutation when it defined the result war instead of the mutation object over here. So going to first of all, define the magician object on here going to be find the name off the result war, which is create tusk. And again it is going to be a function and as we know that we will receive DVDs feels for creating the task inside often input field as an object so I can get it from the arguments object. So festival here I'm going to declare the end of school field for the parent object on I'll basically this structure the input field from here. So this will basically give me the fields that are present over here in the input type which is create task input. And what I need to do is I need to push this particular new task. Insert off task list on for pushing the task Insert off the list. I need to also generate a unique i d for the task. So for donating the unique ideas off Now I'm going to install a pack. It's called as do I d. So going to simply say and install you already on going to use this package? Putin ended the university. So now let's go to this. Our door, Jess. So, as you can see, it is done installing. So first of all, let me require this particular library. So here, going to simply say, const you I d equals to require you ready on. Now I'll basically use this I d on and create the object that I want to create. So here, first of all, I would say const dust he calls an object. So first of all, I'm going to spread of a all the feels that is given by the user. Next I want toe Add the i d for this particular task, which will be unique. I d so here going to simply say you already dark before. So which is going toe done? The unique idea as a string on going to simply say this now will basically push this particular task. Insert off the existing Ari. So going to simply say, task dark Push on going to push this task on going to return the newly created task. So let me say this on. Let's try this magician nerd school. But the browser, the fresh on. If you have a look at the documentation, then as you can see now we can see the mutation says Well, on here we have the create task petition on it basically also shows the argument that this particular mutation requires. And if you click on this, then as a considered exactly sure difficult that is required for this particular type. So let's go to their task ap a tab and here I am going to fire the mutation. So, first of all, you have to specify the type of operation with this mutation. Then you can specify the name off the operation. So let's call it as create task. Now. Here I can simply access the create task imitation and instead of this and it took past the all the information in the input object. So here, going toe first of all positive name has, for example, new task on going toe past the completed status as false. On going toe past the user I d as, for example, one on. As a result, I can ask for all the feels that our newly created. So I lost for the name as well and I'll also us for the complete illustrators. Let me prettify this on. Let's hit this now. So, as you can see, we have this newly created a task that is given as a response from the server. And if I basically execute this, get on task then As you can see, this new task is added over here with a unique I. D that is generated with the U I D package. And of course, it is not going to persist over here because it's off now. We are not using the data base. It is just simply a static Oreo here. So if I basically saved this on like the Normandy start this war, that insurgency often just will be lost, and it will not off course persist. But I just wanted to show you the mutation functionality on that's it for this particular video. And I hope you were able to follow along. And thank you so much for watching this video 18. Modularize Resolvers: Hello, everyone. So in this video, we're going to Marie Le Dice. Art is a word, because as off now we have everything in one file, which is that we're not. Yes, Also, we have this key mind one filed. So we're going to moderates. This came out in the next video, but as off Now let's focus on the result wars. So what I'm gonna do is I'm going to create a full over here, called as it is always. And instead of this, I'll create profiles. The 1st 1 for handling the user result were on the 2nd 1 for handling. The task is over. Now. What I'm gonna do is I'm going to simply copy everything from here on going to pastry inside off the task result word on going to simply say model exports equals an object and going to paste everything over here. And I'm going to remove everything that is not related to their task. So I just remove this great things. I will remove this users as well and also going to remove this user a fair level dissolved so we could remove. This is off Now let me see if this and since our decisions awards are basically using the task and the users constant. Let me put it over here. So one of simplicity users come with us on this basically comes from Constants folder. All right now, going to do the same process for the user. George's Elizabeth. Simply going to copies. Go to these or not. Yes, on going to export this object. So let me paste everything over here and here now will basically remove everything that is not related to the user going to remove this task as well. Just going to keep the two credit over here. The 1st 1 is user second when his user are going to remove this great task. Magician is well on going to remove this task very level. There's always as well on that's it. So our user result what is also ready Now? Finally, what I'll do is I'll create in next door days filing this result and here going to import the weasel word and their task is over from their respective file. So gonna say const users always equals require dark slash user on going to also have the task of is a word on this also comes from the dusk. Now, here I am going to simply export theory off result would on here going to someplace a use that is over on the asked his old one. So this looks good on you can basically pro wait. This array of result wars are two years old. Words instead of the Apollo several configuration. So let me remove everything from here on. What I'm gonna do is I'm going to import the list of its owner from the result or folder. So it doesn't say Const. It is always on This basically comes from the It is always for that on going to make it off this variable over here on. I think I need to name it as it is almost so. It will automatically be used because it is already find over here. So I think it looks good on let me remove this constant in port as well as it is no longer required. And I think we need to move this year already constant inside off their individual. It is always so going to simply important them over here on going to do the same in the user dot Js file is well, and I think we need import the users in their task and sort of the user charges filed. So let me simply copy both off this import. I'm going to paste your door here, and I think you are. It is not required over here. So when doesn't really move this on, let me say this. Now on, Let's go to the subtler refresh the app and let's check if everything works fine. So let me try to hit to get our task. As you can see, it works properly. Let me wouldn't try to get the user field instead of the ghetto task Woody is against. It works fine. Let's try the mutation. It also works fine. Let's go to the user FBI on Let's try to hit the get all use a repeat as you can see able to get all the user and I'm also going to get single user so everything is working fine. All we have done is basically taken up. The is always from here on put it inside off their respective folders on in the next video , we're going to segregate the scheme as well because we don't want toe, you know keep on writing it over here in the single fight. Let's just try toe. Segregate that and you're going to learn a very important concept related toe schema Separation Caldas Ski my stitching. So let's have a look at it in the next video on. Thank you so much for watching this video. 19. Modularize Schema ( Schema Stiching ): Hello, everyone on in this video, we're going to model Arise Are schema on going to place? This task related and they use that letter schema That is their query mutation as well. Esther type into separate file on going toe, combined them into one file and will pass that particular combined schema for the Apollo server. Instance. So this process off combining multiple schema from different places, is called us asking my stitching now, One important thing to note here is that in your entire schema, combining all the separate schema, there can only be one good level type in your skimmer. That means there can only be one credit type. There can only be one mutation type on. There can only be one subscription type. So if you want to define the separate schema for the task and separate schema for the user unit to off course place de querian sort of de Quito type, right? But as I said, there can only be one road level query type. So how can you basically define separate ski mind multiple files and still place them inside of the quality? So I'm just going to show you the solution in a bit, but let me even try toe exactly show you the problem that we have all here. So, for example, if I declare another credit tip over here on, let's suppose that I have any feel over here, for example, test and I'll specified as a string. Not if I see if this there scored their terminal and see whatever do we get. So as you can see, it says, there can only be one type named query that wins. There can only be one road level query type now alerts five for the mutation as well. Let me see if this let's go to the terminal. The NASA concert says there can only be one type name mutation. So let's see, How can we define the multiple queries in separate files and multiple mutation in separate file, But it's still placing them under the root level type so you can do it using the concept off extend. So what this extent keyword will go, It will basically extend your base type on. We'll add more fill story, So let it be this explain you by example. So, for example, here we have type user now what I can do is if I want to add more filled toe, this particular type, I can simply say extent type user on here. I can add more field, for example, address on I'll just, for example, keep it as a string. Let me see if these on as you can see there is no odor. Let's go to the browser, the fresh. And if I go to the documentation on defy, for example, goto this any off this user related query on as you can see in the type user. Now we have this new address field that this added just by extending the base type and do not confuse this extent keyword with the inheritance concept that we have in the object oriented programming. Because this extent give it is not creating a new type. It is just extending the base type. As you can see, there is no new name for the site that we just created. We are just simply extending the user type. We're not creating a person and extending dead, so I hope you understand now on. One more important thing to note here is that you cannot extend empty based type, so that missy of this. As you can see, you will get theater, and in fact, you cannot even have an empty types. So the reason you cannot extend OMT type is because you cannot have empty type Insert off your schemer. So, for example, if I define our type called us address and if I keep this empty, save this then, as you can see, you cannot have empty type in sort of your schema. So now that we have understand the concept off extent type, what I'm going to do is I'm going to create separate schema files for the task and for the user on going to extend the base root level query type, Select winters Do it now. So festival here, I'll create off older Calder's type deaths on in sort of this idea create to fight one for the task on one for the use it on. What I'm gonna do is going to the several George's on going to simply copy all of this on going toe. Hastert, over here in the task door chase file on First of all, going to import the sequel from the Apollo sort. What express? Gonna say const equals equals required. Apollo side will express on Dhere going to simply export this particular schema. So when it's a model dot export equals this. And in this file, I'll only keep those data which is related to the task. So going to remove the greetings from here, we're told him off the user related information from here on will keep the creators in port cities will keep the create task Mutation also on will remove the user type from here, and we'll keep the task type as it is. No alerts to do the same for the user. Georgie s as well. So going to copy this, goingto pasted inside of the user, Georgie s going to simply export this thing on going to importante Dicle from Apollo's are over express on dhere. Also, I'm going toe Keep the use of military information on Lee. So going, touring on this task later information going to remove this thing as well and going to remove this Create ask mutation as well. Is this tight mutation because I cannot keep any type as empty as we just saw in the example so that maybe move this on going to remove the task type as well so I think we're good to go. Now. All I need to do is I need to combine this schema and export them on provided instead of the Apollo. So, for instance, so here, in their time definition, I'm going to create index dot Js file and here I'm going to first of all, require the user type definition on this comes from dot slash user next going to require the task definitions on this comes from the task Gorgeous file on here. I'm going to create our base tape for other tapes to extend. So here, going to simply say cons id efs equal toe Dick you'il on going to imported equal from the Apollo Software Express. So here, going gonna say const equals equals to require Apollo said would express on here inside of the vehicle, I declare the base root level type. So it is type query on here. Also declared the type mutation. And what I'm going to do is I'm going toe extend this road level type inside of this separate fights. So here, going to simply say extend, let's go to the task Js file on here. Also going to say extend for the road level, Corey, type on extend for the work level mutation. And as we saw that we cannot have I'm type and neither can we extend our empty type. So here, just for the sake off having something as a placeholder, I'm going to just declare under school so they're declined. Doesn't get confused whether it is a real query or not, this is just a place holder so that the other type can extend using this base type on going to do the same for the mutation as well. And you can keep the type whatever you want. This is just a placeholder query and a mutation. It has nothing to do with the eyes, all what it won't have. And it is always we are just keeping this. So there's gotta be a state is not empty, and other type can basically extend it. And finally, here. What I'm gonna do is I'm going to send us a model dot export on here. I'm going to specify the base type definition, then going to be find the user tap definition on, then going to define their task type definition on finally going being bored. This type definition in the starboard or Js file on going to specify door here. So let me remove everything from here on Finally here, going to simply say corns. Definitions on this comes from type definitions folder on that sip. So let me see if these on let's go to their terminal and test. So as you can see this always running find like school to the browser and they're fresh, let's Goerdeler documentation on. We have this place order feel that were added in sort of the base query and the magician type, and we have various other equities and imitation that we have defined now. Large test all of our A. P s now. So if I basically test the all user then as against it works fine, it's does the good use a variety? It is also working fine, alleged as the list off task. It is working fine. That's does the get tough squarely. It is also working fine. Let's also tells Dick, create us. It is also working Fine. So you guys, that's it for this particular video on. I hope you were able to understand the concept off schema stitching on. I hope you were able to follow along. Thank you so much for watching this video 20. MongoDB Connectivity: Hello, everyone on In this video, we're going to do the mongo DB database connectivity. But before they're now like pretending that I have renamed the existing project with the graphical Apollo High Fun Part one. So what they were called we have returned till now will be available in this particular folder on What I've done is I've created a separate folder for whatever court that will be writing from now because I wanted you to have access to this particular court. Because if I start making changes in the existing court, then a lot often just will be lost that we have done over here. So you will have both this or scored in the resources section up total. Now in this particular part one and I have created the part, too. As you can see, here is the part. Oh, and it is containing the same court of is that we have predicted. Now on. Even if you have a look at the terminal. And as you can see, I'm running this and Pam Brando in the graph, we'll high findable Ojai Funny behalf on part. Oh, and everything working as it is. So I simply created a new folder so that we can make changes to the further court on still have access to the court that we have returned to allow. So now we're going to work in this particular directory. Ondas. I don't do this containing the same code base. So now let's implement the mongo to begin activity. So to interact with the Mongo db, I'm going to install a library. Cordes Longo's on its an object data modelling library for mum Would even Norges so going to simply install this? And by the time this installing, I'm going to create a folded over here called US Database. Insert off this. I would like to create another folder called As You Do on Internal Do You Till Going toe create index charges filed on. As you can see, this is done installing. So going to simply close this on festival going to require the Mongoose Beckett So here, going to simply say, Mom goes on going to export method away here called as connection on this is going to be a function on here, going to simply say Mango's not connect on in the force argument. You have to pass the database well so we like to fetch it from the environment. Variable on the name of the variable. I would like to keep it Mongo underscored baby underscore you are so let's define this particular You are inside off the dirty and we file So here I'll give the Urawa's mongo db colon slash slash local host slash name off the database. So let me simply call it my baby. Let me see if this let's go over here and here. In the second argument, you can pass sponge off options. So the first option they're not going to pass is used New York parcel on going to set it True. This'll is required for the New York version off mongo db On in the second argument, I'm going to pass another argument. Carless use unified topology. So this confrontation is required for the latest version of the Mongols liberally to make the mangoes work properly on Disconnect Met her, basically redone, so promise so I can make it off the await keyword away here on to make it off the keyboard . I need to make this function. You think now, if any sort of error occurs, then I would like to handle internally trinkets block because if this promise fails, then over a keyboard will basically told the other. So going toward the track, it's broke away here on going to move this statement over here on in gets off success. Going to simply console log data is connected successfully on in case off any other going to simply console log theater on going to simply toward the other. So I hope this makes sense. Let me say this. Now let's move on to this award. RJ's file on here. I'm going to simply say below the comment over here called us DB connectivity on going to require this connection method from the tub Sutil file. So here, going to complain board the same. So I'm gonna go to the database, slash your bill, and I would like to get the connection my third over here on simply going to simply say connection. So that's all you need to do. Now. Let me see if this on large her toe with your terminal and see what happens, says you can see it says database connected successfully. So I guess that's it for this particular video on. I hope you were able to follow along on. Thank you so much for watching this video 21. User and Task Mongoose Schema : Hello, everyone on in this video, we're going to define this schema for their task and the user. So here in the great Abyss folder, I'm going to create for their Cordless models. On inside of this I'm going to First of all, they find the schema for the user. So here, going to create a file called its user on festival here, going to require the mangoes. Solana said, Const bongos equals be quiet Mangoes on here going to simply say const user schema equals two new instance off mangoes dart schema on. Instead of this, I'm going redefined the field for the user so users will hold fields such as name on. This is going to be off a string on and keep the required as true Next one toe have the midfield on it is again going to be of type string on it will also be required as true. Next, we will also have the passport for the user. So when do any door here is one on again, it will be required. Ondas We know that the user will have one to many relationship with the task model. So here we need to define the relationship between the user model and their task model on. We're yet to defend their task model, but let me just at this over here. So it is going to hold the list off task on each item. Inside off the task will be off type mangoes, dart schema, door types, your objectivity. So every unique idea there, distended by the mangoes, is off special type called us object. Ready Hence, I have defined the type as objectivity and then you have to define the reference so I'll keep the their friends as task on this. Basically, they're forced to the model which we're going to define it soon on. Here at last, you can simply say model North export equals mongrels. Dark model on you can basically passed the model in which issues er on. Then you can pass. This game averages user schema. Now, here in the mongooses schema, you basically first of all, defined the schema in the first argument on in this second argument, you can pass various option So here I would like to pass option called this time stamp on and said too true. So what this will do is it will automatically cleared the created at and the updated at field. So it is ultimately going to do it. You won't have to minutes anything. So let me say this now it's time to create the task model. So here went to simply say, task. Georgie s on going to copy everything from here, just going to simply update some of the things. So for stolen named him or the less task on I'll basically the place this thing as dusk schema on for the fields. I would like to have the name over here on the next. I would like to have the completed field which will be off of bullion. So let's define it over here. And since the relationship from the task to user is many to one so going to define their relationship over here, So going to first of all, dream on this on here, going to simply say user on this will be off type mangoes. Dart schema dot tapes dot objectivity on Bill referenced Immortal s user. So going toe defined using the ref at tribute on here, it will pass the user model. So I hope this makes sense now. And just to read right over the relations. The user is going toe. Hold the list off Task 80 that it has and task is going toe Have the user i d. So that means a single task will only have a single use ready But a user can have multiple tasks. So that's why I have defined it like this. So it is. That's it for this particular video. Andi, I hope you were able to follow along. And thank you so much for watching this video. 22. Signup Mutation: Hello. Everyone on in this. You know, if you're going to perform this and up mutation, But before resorting for that, I would like you to download this particular tool called us for about 30. So if you basically visit robe among or door towards e slash download, then you can simply don't lord it over here. And they still basically provides the do y for interacting with the Monterey Bay database so you can perform all sort of operation such as create up there dilate and less documents , as well as dropping collection, creating collection, things like that. So it's a very handle on this story. Treaty is appeared. One on this one is basically free. So you can basically don't want this robot pretty on. Once you do, it will look something like this. Let me just show you you can simply can connect on here on the left. Inside, you will see all the database you have in your longer DB, and we're going to explore this tomb or as we proceed further, but as off No, let's continue with the Senate tradition. So no, I will basically go to the art type definition for the user on going toe. Create the mutation for the sign up because it will change this straight on the back end and some defending the magician Nordic query. So here, when doesn't place the extent mutation on here going to defend the mutation as sign up on, we're going to expect some of the fields in the arguments on we will have to accept insert off the input object. So let me create our input object called as sign up. Input on this will basically return the user on. Let me create this import over here. So gonna simplicity in port sign up in port on here. We're going to ask couple of things such as? For the name on this will be noncallable string. We'll also ask for the email on this will be no inaudible string as well. On we launched Waas The password on this will be known a liberal string as well. So now we have this ready. Now let's define this mutation in the result would. So let's go to the user door chase instead of the result war on here in the mutation going toward we find this an amputation and here goingto defined it is a lower function and instead of this world will do is we will first awful it try to grab the arguments over here so that we can perform the sign of operation. So in the first parameter, we have the parent objects. You're going to ignore this one on in the second argument, going to restructure the input object from the art object. And now we basically important the user model so that you can perform this sign up. So here, going doesn't say const user requests to require on I can get it from database slash models slash user Now, first of all, we need to check if the email that display roided by the user in the argument already existing the system or not, because we don't want to desert to sign up with duplicate emails. So here I am going to query the mongoose model so we'll know. Simply say, user Dort, find one on here. You can basically pass the field that you want to find, so we want to find the email and I can get it from input. Dark email on this basically returns the promise, so going to make it off the await keyword and to make use of the over keyword I'll make this function is ink on would like to put everything inside of the track. It's block so that if there is some merit, we can basically handle that error. So that made it over here. I'm going to move this thing over here in case of any other simply going to console log the era on going toe for the other. So gonna said, throw better. And now, once we have the user over here going to simply get it inside of a constant on here, going to simply check if user exist. So if the user is not found with the given email, the user will be no. So I can simply check if this particular thing is normal on If this is true, then I would like to simply for the other. So when I said through new era and I would like to pass the message has email already in use on If this is not the case, then we can put it for their with this and a process. Now, before creating the user in the database, we need to first of all, get the hashed password because users will basically provide the password is a simple string over here. But instead of the great abyss, Nieto has the password so that it is secured. So for hashing the password, I'm going to make use of celebrity called has been gripped. So gonna saying been stall Big trip, Jess on. Once this is done going, put simply makers off our method available on the crypt library called as hash pretended be hashed password. So let me exit this on here, going to require the library. So when I said const big ripped equals required bigger objects on going to move this thing over here so that we have proper segregation. But when the library imports were says custom violin boats So here we go someplace a const hashed password on going to make use off the big trip dark hash function on here. You need to basically passed the plain text instead of the forced arguments of understand Melissa input Dark password on in the second argument unit to either passed this sort string on you can generate it using the same library. Or you can let the big replied really generate disordered for you. So we're going to go with this second approach. And if you want to be cripple really toe under the hash for you, then you need to pass the number, which is called us. Sorry, drone, and it basically determines how complex it will be. Toe has your password. So the gentle recommended range for the salt wrong is around 10 to 12. So I'm going to past well over here. And this also didn't promise. So going to make it off the obit keep what we here and now here, I'll simply say, const new user equals two new instance off the user model on going to simply first awful pass. All the feels so going to spread over the input on I would like to know where the password field with the hashed password. So what, this will object will hold this basically name email in the password on. All we have done is over. I did the password field with the hash password. Now, finally, all you need to do is to simply say, new user dot C on this also basically returns the promise. So going to make it off the operating table over here and here going to simply say construct desert equal tothis andi finally going to simply return the result. So I hope this makes sense. Let me see if this now let's go to the browser and test. So here, going to simply go to the local host 3000 ones less graphical on instead of the user tab here, I'm going to run the mutation operation. So let me call this operation as could you get to use it. And instead of this, I'm going good on the sign up mutation, which is the actual name of the mutation on inside off this unit, to pass the argument in the input object and instead of this unit to pass all the three fields, which are name, email and the password, because all of these are not available. So you're going to some place a name on with space where David then specify the email as, for example, David had great gmail dot com. The night is specified. The password on that will be 123456 On as a response from this R word, let's ask for i d lets us for name on. Let's ask for email. And now let me prettified these. Andi, run this then. As you can see, we got the response from the server. Let's go to the robo Three tittle and take if there is user in the database, So simply click on the fresh over here. The NextGen see here is that my DB database? If I go to the collection, go to the users then, as you can see here, is the user created on here. You can toggle between various views such as this view on the table view on this kind of you so you can use it as put your convenience on If you have a look at what? The passport carefully. Then. As you can see, we have the hashed password over here. Onda, if you're wondering that instead of the great abyss we have, the underscore I d Field on it is holding the unique I d for the user. But instead of the user graphical schema, we have the i d. So how graphical actually mapped the underscore? I d So the idea field on the user type schema on returned the idea We're here. So how that actually happened? So this actually happened because off the virtual ghettos concept in sort of the mangoes. So what actually happens is that whenever you create e d mangoes Onda, whatever result that you get from the mangoes mangoes at that some more failed store it when off, Which is the idea virtual greater. And as soon as you did on the result from the Sinem Result word, the draft will is able to pick up the idea field from that idea Virtual gator. And you can read more about the idea virtual gator on the Mongoose documentation. But here, let me to show you by adding a console log. So here I'll basically first of all council log the dessert dark underscore i d. And I'll also speak for the type off result Dart underscore i d. And then I'll also specified the different over here on this will be desert dot i d. So let me say this election writer and this So, for example, if I run for another user card as Kevin and I'll name the user s Kevin, if I heard this now let's school for their terminal then, as you can see, here is the underscore I d, which is off type Object on Dhere is the result dot idea virtual greater which is off type string. So the graphical is actually picking up this from the result object that we return from this particular result work. It is not picking up this thing. So this is how it's happening on. Let me remove this console up. From here on, there is one more thing that we can go, which is toe addict created that field and the data tight field on the user type. Insert off the type definition because since we have specified the time stem both of this filler president so lets at this will to the user type. So here windows in places where the field name we just created Andi specificity type as a string which will in on a level because every record will have the creator that and the opera direct field on Dennis space with the object attacked field on again. This will be off type string and it will be known the level So let me think this alert school to the browser and test Let me to fresh this on here All provided Newman, for example John at the regiment dot com on for the name. I'll simply say John on, Let's ask for the created that field and the operative that field and let me hit this now then, as you can see, we get the created act and the abducted at field. But one difference you would observe here is that here we are getting this field as a UNIX time stem. But in sort of the great abyss, let me press control, are toe, refresh the collection and get the latest record. So instead of the database, we have the date as I sorted. But here we are getting the UNIX times them. So why this is happening? Well, this is happening because we have specified the created at and they operated right field, off type string. But instead of the database, it's an object. It's not a string. If this was simply a string, we would have God the same string over here. But now, since it's an object and it's an eye assorted object, so workers after price to do it tries to convert this object. So this string and in that conversion process, it actually converted the I so did to the UNIX times time, Andi, That's how the graphical works internally. So one of the solution to fix this problem is to define the custom scaler type over here, which we're going to do in the next video on that type will be able to handle. I saw object data as well, but as off no, just to explain you the situation more clearly and simply copy this date string on Let me go to the user Result war And here I'll add a fill. The level result were insert off the user type So let me add Ofri level result were called has created at and here going to simply return i assorted string and let me say it this on this is just to explain you that the article is not trying to convert the string date into their time stem in fact, that this train look inward the object I sorted into their times them. So let me see if this let's go to the browser. And now, for example, if I basically test with another user called as best user and that is specifically name is test user and if I heard this now, then as you can see for the curator that we got this impulse string. That means if instead of the database, this was just a simple string, not the I assorted object, then we would have got exactly the same string that we have in the database. So I hope you were able to understand this on. Let me remove these free level dissolve word. This is not an addict is to explain you. So it is their check for this particular video on. I hope you were able to follow along. And thank you so much for watching this for you. 23. Custom Date Scalar Type: Hello, everyone. And in this video we're going to implement the custom. Great skill, a type toe handle, the ice or date. So for that, I'm going to install a package called this Graphic Equaliser date. So that missing Do it So here gonna send PM stall graft. You'll hyphen I so high funded on this particular package basically probated the eyesore Daytime's killer type which we're going to use. So let me simply exit this now and I will basically go to the our type definition on Dhere going to first of all, declared the customs killer name. So the way you do word is by simply Singh's killer And then you have to specify the customs killer with this date. So now we need that is over for this particular customs killer. So let's go. But the result wearing next arches and here going to first of all injected is over from the graft relies So big package. So here, going toe import from the the actual I sorted Onda, we basically need the graphical daytime this all over this peculiar pretty basically exposed three scaler graphical date, graphical date time and graphical time. We want to handle the date and time as well. So going to use this particular skill. Now let's use this killer. So gonna simply said const Custom date skill. A result word on it is going to be an object on. You have to specify the name off this killer, which is dead, and then I'm going to pass the graphical daytime skillet over here. So this is going to resolve the date on. All I need to do is to use this particular result lower and export it over here. So I hope this makes sense. And now what we can do is we can go to the user type definition and instead off string, weaken. Basically, use the customs killer that we just define over here in the index tortillas, which is dead. And I'm going to do the same for the operated at field as well. So that missing of this let's go to the terminal. As you can see, everything is working. Finally, Now let's go to the browser and the fresh. And here first I'm going to hit this Anna BP with the user that already exist inside of the database on If we do so, we should get another. We'd intestate this interview in the last radio, but let's go it now. So if I hit enter, as you can see it says email already news. Now if I basically assigned with some other users, for example, Bob 22 word that it's similar com on for the name of I'll say Bob 22. And if I heard this? Now let's see what happens. So as you can see now, we actually guard the exact I started studying, as we have inside of the database on to see the latest record, you can simply right click on you can in short press controller. Or you can simply click over here on the re execute query. Then, as you can see, here is the new record on As you can see, we have the same date that this president over here on the same date is basically returned over here. So now we have this custom dates killer working fine on you guys. That's how you implement the customs killer. Andi, I hope you were able to follow along and thank you so much for watching this video 24. Authentication: Login Mutation: Hello, everyone. So in this video, we're going to implement the authentication using Jason Ripped Open. So we're going to create the logging mutation using which user can authenticate and get digits in Web broken on. We will use this token to protect other a PS, and we're going to see how can you protect your A P A in the upcoming videos. But as off now, let's try to implement the logging mutation and let's written the token back to the user. And if you're wondering why the Logan has to be mutation North Equity, because the logging is not going to change any data on the back end. But there can be something. Are you where you want to lock some user activity as the user logs in hands? It is a good idea to keep the logging as a mutation, and I also explained in the graphical schema basic video that in the query run simultaneously and the mutation runs sequentially. So let's assume a scenario where you're defined the logging as equerry on Let's say you basically fire occurred at the same time. The 1st 1 is the logging. Andi Second quarter actually depends on the user authentication state, Let's say the second queries for fudging the list of items. So as we know there, Dick waited and simultaneously. So it is a possibility that the list of items runs first before even the authentication step is completed. And you might get the authentication error from the list query because the user is not art indicated yet, of course. And so you should basically defined the logging in sort of the mutation. So now let's proceed further with the defining. The logging is imitation, so you're going to simply say logging. And instead of this, I'm going toe ask for the import on the import that I want to name. Here is the log in input on this will be off type token, because all I need to do on the successful authentication is to simply do it on their token . So let me define the type token over here on this is going to simply have the token on which will be off type non a level string on. Now let's defend the logging input. So here, going to simply say, input on the Logan input and all of one from the user is the email, which will be off type noncallable string. And the password on this will be off type normal level string as well. So let me say these are type. Definition is ready now Let's right. There's all were for the logging. So I'll basically go to the users over. Fight on here instead of the mutation. I'm going to create the over for the logging on. It is going to be a function on for the force perimeter. I'm going toe escape, which is apparent object on for the second parameter. I'm goingto be structure the input from the art object that you get inside of the resolver function. Now, while first of all, check if use that exist inside off the database before checking the password. So here, going to simply say, const user equals over it, user dot Find one and you're going to pass the email from the input 40 mil on. Since I'm using the over keyboard over here, I'm going to make this function easing and would like to put everything inside of their trackage block so that if there is some error, we can easily catch it. So here, going to move this particular statement in sort of the tribe lock on instead of the catch block going to simply console log the error on also going toe theater. So gonna said through no here. First of all, I'll check if the user personal. So if the user is not found, the quit is going to return on. So in that case, I'm going to simply for the errors. So when I said through new era and going to pass the message as user north phone on, if the user is phone, then we can push it for the now. The next step is to check the password, so use it is going to send the password in the plain text string. But instead of the database, we have the hashed password. So when to make it off the big rip library, basically, compare both off the passwords or when I simply said, const, it's password. Well, you'd on going to make it off the big rip levity dart. Compare Mentor on these Basili returns a promise you're going to make it off the of it. Keep it over here on. Instead of the fourth argument, you have to pass the plain text passwords so I'm going to simply say, input your password. And instead of the second argument, you have to basically passed the hashed password so we can get the hash password from the user daughter bus word. And if this particular password is not valued in that case, I can throw up. So let me simply for the other over here on for the message I'm going to simply say invalid bus word on. If the password is Walid. No, it's time to create the token on. I'm going to make it up digits and wept O'Connell ability to create the token. So simply going to go over there terminal on here. I'm simply saying, PM stall just on were broken. So as you can see, the installation is done. So going to simply close this on, I'll basically require this particular library. So when I said const, JWT calls to require Justin Webb. So you're going to say const broken equals jwt dart Sign on these basic leader dancer string on default argument. You have to pass the payload on this payload is completely visible even without the secret key, so make sure that you don't put any sensitive information over here on try to make your payload as smallest possible, because if you put a heavy object over here than your token size will become quite large and human face on issue while making the bill called. So make sure you have the Baylor as smallest possible on Do not put sensitive information over here. So for the payload, I'm just going to simply put the user email so gonna simply say, user dot email. And in the second argument, you have to provide the secret key so I will accrue defined the secret key in the involvement file on here. Going to name the cigarette Kia's JWT secret underscore key on for the Velux Windows. Invasor tests at the right. 1234 on Going to use this particular key over here. So going doesn't place a constant secret equals festival. I will have to fetch it from the environment. Variable on. If it is not found going to make this offer the Ford secret key on Let's name it my secret K. You can name it whatever you want on going to pass this secret over here and in the third argument, you can provide various options such as experts in there to rebuild on this is going to basically are defined at wartime. The broken is going to expire on this. Where is the former? Off the expedition babies concern. You have to specify the exploration time in a special permit. So let me just show you. So if you basically says for the PM Jason Webb Kogan Page, simply go over there. And if you scroll down, then, as you can see, here is the example of how you can pass the experience at too good. So how this format works is if you basically specify the number than it is going to be treated as second. If you basically specify the number in, turn off a string, simply number not any units such as the is ours, except then it will be considered as a millisecond. And if you specify the units such a seven days or 10 hours, then it will be treated as it is, so you can read more about this year time. It's time for Mitt over here now. I'm going to set the expert E as one day over here, and at last I'm going to simply read under Erdogan's I wanna say Return on going to pass the token. That's it on. Remember that this thing is equivalent to this. I'm using the six shortcut. So let me shorten this on. I will also update the password message over here in Start off Invalidpassword. Let's call it incorrect Password on that makes more sense. So let me see if this now and I think we are going to go there to go to the browser on simply the fresh tasting and here going toe run mutation on. We'll call this operation as logging and would like to access the log invitation on. Instead of the argument, you have to basically provide the email and the password. So let me throw it or email, which doesn't even exist inside of the database and let's see what happens. So, for example, if I provide any random email over here, which does anyone exist in sort of the system under employed the password as well? Because it is a required field on in the response. I can expect they're broken. And if I heard this now that is again See it says user not found. Now let's test log in with User, which does exist in search of the database but will pass the incorrect password. So if I go to the baby now, let's try to pick up John and Reggie Miller. Come So here. Going to simply say, John ed regimen dot com And, for example, if I pour penny wrong password If I hit this now, then as you can see, it says incorrect password. And finally, if I pulled the correct email and the correct password on, Let me hit this now then, as you can see here we have the Jason ripped open and as I was telling you, that all the content off the payload is completely visible. So let me just show you if you basically go to the JWT daughter, you on a few basically based your token over here. Then, as you can see, the payload is completely visible. You don't even need the secret key to see the payload hands. You should not put any sensitive information or here. And if you're wondering that if the payload is completely visible, then how is disease and reptile unsecured? So remember that depart post off the Jason Ripped open is not to security data that this president insert off it. The purpose of the Jason we're talking is toe authenticate declined, which is making the request. Andi, that's it for the love in authentication on in the apartment videos. We're going to use this token to protect our various FBI. But that's it for this particular video. And I hope you were able to follow along. And thank you so much for watching this video. 25. Resolver Context: Hello, everyone on In this video, we're going to talk about the third argument in the result or function, which is context object on this context. Optic is usually used toe share the common data across all the result hours. So if you want to share some of the atrocities, the authentication state and various other functionality that you want to share with all the result wars than it is better to pass it as a context. So let's see, How can you passed context toe all the result of ours from your Apollo several configuration? So let's go over here and here you have another argument. Cordes Context on this context can either be an object or a function on. I'm going to show you the difference between both of this, but it's not going to use the object. Then we will use the function. So let's suppose that instead of the context, I want to pass the email off the locking user on as off now, going toe hard court this particular email. But later on in the upcoming videos were going toe there. You'll user email over here, which is locked in. So just for the sake off testing like me at the Mehlis test at the rate gmail dot com on go now, this particular object can be accessed inside off any off the result for function. So now we're supposed that we want toe access this particular email insert off a particular user to sell a function. For example, get user by 80. So as the context is available instead of the third argument on, I'm going toe basically the structure the email from here. And let me simply add the console locks whether you can see properly. So here, going toe singly, Erdogan's a log. So when I say consumed, not log on, going to simply train toward email on here, going to return the result. So let me see if this now on. Let's go to the browser on. Let me refresh this on. Let's tryto down equity called us. Get user on here. Began around this particular quarry here will provide the argument is, for example, one on in the response will ask for I d name like Mary Tender and as off no. These responses coming from the static data. But later on we went to replace this with the user model, but it's often let's focus on the context now if I go to their terminal. So as you can see here is the email that we got from the context object on this particular context. Object can be accessed. Insert off any result war. So I hope no, you understand the concept of context. Now let's look at the use of second applause, which is to declare the context as a function, nor does object. So if you're declared the context is an object, you can rt in this later on. You cannot add dynamic values to it. So this particular level beside when you saw over starts on for ET request. You cannot change this value. So let me show you by example. So, for example, if I add Matt Dark line number over here on, if I see if this the next agency the Soviet city started now the context is said now. No matter how much time I hit this a pia, I'll always get the context as the same hesitancy. But now, if I declare this context as a function, it is going to run every time there is a AP request. Toady craft girls over. So if you want to evaluate something on per request basis, then you should declare this context as a function. So let's declare this context as a function on. What I'm gonna do is I'm going to return an object from here on going to move this thing inside of the object. Let me see if this now now let's go to the browser. And if I try to hit this 34 times, then we should see different values every time. That means this context is running every time. And let me when I had taken so long over here on doesn't place a context ran Let me see if this let's go to the browser. So if I heard this request 1234 times, then, as you can see, we have this context lock four times. So I hope now you understand the difference between declaring the context as an object. Warsis function Andi. Generally, in a real world scenario, you will always declare it as a function because you want to evaluate something on each request, such as the authentication state. So once the user logging is completed for each AP request, you want toe check whether that user is logged in or not, or whether they're user is valued or not. So you should use the context as a function service. That's it for the context concept in sort of the graph girls over. And I hope you were able to follow along and thank you so much for watching this video. 26. Verify Token and Set Auth Context: Hello, everyone on in this video, we're going to wait. If I did talk on that will be sent by the graphical client and we're going toe said the authentication context. Or hear visual dynamically get from the coconut descend by the user. So let me show you how they broken will descend from the graph we'll client So if I heard this particular AP which is logging then, as you can see here is the token and all of you need to do is to simply go to the extra beheaders on you basically send the decent Republican instead of the alteration beer header . And that's in standard for how you said the broken inside of the alteration header. So here, going to someplace a tradition and here in the value, going to pass the beer space, the token. So in this format, the plane will be sending the token on. We need toe authenticate this token on our server and accordingly said the user context and if they're talking, is in very than the alternate toe returned the air. So let's implemented now. So we want to basically check this took on on each and every request right so once the user results indicated on it has the broken. Then for every request we need toe check the token on get the authenticated user to instead of writing the whole logic over here in the context function, I'm going toe separate the larger in sort of a separate folder. So let me create Folded over here called as helper and insert off this I'm going to create another folder called s Context On Inside of this going to create a file called US Index Tartous and you're going to say model dot exports dark verify user on it is going to be a function ondas off. No going to simply import dysfunction on place it inside off the context function. So let me imported over here, so gonna say const and I'll get the very for user function from the health for folder insert of this. I can get it from the context. And now I'll get the verify user function over here on going to simply call dysfunction from the context because we want to run this function, which is going to evaluate the Justin ripped open for each graphical request. So going to call it over here. So going to simply say verify user on here, going to pass the request object. And if you want to have access to the request object over here, you can get it from the context function argument. And here in the context argument, you have access to various objects when off it is the request. Objects so going toe to restructure the request optic from here on going to pass it to the verify user because the broken will be send inside of the request header. So we need to have access to the request object at least 2% for the So now let's go over here and now I'll simply control or be requested headers over here so that you can see properly worse, the value off the same. So let me console actus and your let's try to hit the request and see what we get. So if I go to the browser and if I hit this, for example, get user request and if I go to determine then as you can see, here is the request header information, and inside of this we have the token over here in the alteration key on Devalue we have beer space token, and this is what we have passed from here. So let's feds do you talking from the harder so here and say const, be it up ahead of on I can get it from the Quest Dark Haider's dark authorization. And if the theatre had it is found, then I'll pose it for that. So here, going to simply say, const broken Andi, I can get it from by splitting the string like Mila show you so requested. Haider dot alteration Wilder it on this a string. So now I can split this spring with divide space. So which is going to return? Are a containing off the item? The 1st 1 will be here on the 2nd 1 will be the token itself. So here, going to simply seconds, Taconic will do be a header dot split ongoing displayed using divide space on going to access the first index. So now let me I deacon. So lock for the token. So when I said token on going to simply console, log it over here and let me say this, let's go to the browser and had this again. Let's see what happens. Let's call it their terminal then, As you can see, we have the one over here. And now we can use this token and verified using the JWT liberally. So let's import the general delivery. Or here so gonna say const JWT wants to require Jason was talking on here. Gonna say jwt don't verify. And instead of the verify, you have to pass their token. So we do have to talk it over here on in the second argument, you have to pass the secret key so we can fetch it from process. Don't envy nor let me grab this cigarette Keenan from here, which is JWT secret key on If this is not fun, then I can also passed the default secret gave it is my secret key, Onda. Once the verification is successful, we will get Depay Lord. So now grab people over here And if the verification fails, then the JWT will throw the other. So let's handle the other. So going to add a try gets block on in case of any other going toe. Throw the edit on also do at the console log off the other on going to move everything from here instead of there. Try block Onda, once we have the payload or landed to do is to simply say, request dot email equals a lord dot email because we are setting the email while signing the token. So if you have a look at the user is always whenever we basically tended, they're talking, we're setting the millions of the payload. So if the verification is successful, then the payload is actually returned on from the payload. We're accessing the email and setting. Put the request object on Dhere, Going to initially said the request dot email equals no. And now I'm going to remove all this control. Look from here and now, Instead of this award gorgeous, I can basically said the email from the request or email instead, off that static email Onda. If the verification fails than this, email will be null. As you can see, we have initially subject tunnel, and if everything goes well, then the records start. Email will be the actually email off the user who has developed open, so I think we're good to go. Now let's test this on. One more thing I would like to do here is toe make this very far user racing because although we are not performing anything task over here. But still you should make it a thing because maybe you want to perform some Mason convinced . Ask in their case unit toe. Wait for this thing to resolve before setting the context. So even though we're not performing any facing operational here, still, I'll make this function easing on Dhere. You can simply away over this function, and you need to make this context function. Issing to make it off the other cured. So let me hear this. Now on, Let's go to the browser on Let's test know what to beget. So let me go to the browser and I think we're hitting the Galatasary PS. So instead of the guard, use Arabia, we already have the control. Lakoff demon. Now we should get the logged in user email. So we actually generated this broken with the Jonah Dread gmail dot com. So here in the console log, we should get the Jonah regimen dot com. So let me go over here and simply hit this and let me go to their terminal. Then, as you can see, we get the Jonah regiment dot com And if I provide anything wrong over here, let's see what happens. So if I put in one token on, if I hit this again then as against here, it says invalid token on dismissal is generated by the JWT library during the verification over here, as you can see. So if deprivation fails than it is going toe or the other with the message on the hands were getting this message on it is one more thing. The meaning which is to restrict the access to the credit or the mutation if there is no header past. So let me remove this on. If I hit this now, then as you can see the get data. So this time we're not getting any other because a Z can see we have applied. And if check over here. So if if the better head it is not found, then we don't take anything. Hence there is no headed. And the context creation is successful because there is no headed. Of course on the request, email is no so there are multiple ways to handle. Listen, are you the 1st 1 is to simply check here. Like if the quest gorp email is no. Then you can simply throw another from here so you can simply state through a new era on you can pass the other message as access denied. Please log in, so continue. But this is not a good idea to place it over here because this check is going to apply to each and every Kredi in the mutation, and we don't want to check their talking on it. And every mutation, for example, for the sign up. We don't want the token to be possible. The user and also for the logging A b A. We don't want the token to be passed by the user, so if you put it over here, you won't be able to hurt any FBI without the broken. So let's go to the president as this. So as you can see, if I hit enter it says Access denied. Please log in to continue. But now, if I had the love in a B I, I'm going to get the same message, which should not happen, and same for the Cenepa as well. So it's not a good idea to put it over here. Now. You might think that we should put this logic insert off eating every resulted in, for example, the user detail appear. So if I put this thing over here and here, Alexis, the email nor the request, Jody Mills, because we have the email in the context or here. So if I put this thing over here and if I go to the browser and test if I had this again, then it says Access denied Please looking to continue. And if I hit the log Napier, it works totally fine. So this is a working solution. But it's not an efficient solution because, let's say out off 20 AP, you need to secure 15 AP, right, So in each and every 15 days old were you have to paste this thing and it is a deputy to court. So to get rid off this repetitive check inside off eating every result were were going to make it off. The result, middleware or combined, is a word which we're going to see in the next video, but it's often on that's it for this particular video for verifying the token on getting the orthe context. So thank you so much for watching this video 27. Combine Resolver/ Resolver Middleware: Hello, everyone on in this Ridulph, you are going to implement the common result wars Or you can call it a weasel Words middleware. So we want to basically abstract over this logic on Do not want to repeat this logic in every result. Instead, we want to write it at one place and it will be it is all over the middle where, and we're going to use that middleware on various result wars so that this particular logic is abstracted away into the single file on. We don't repeat this. So for implementing the result all middle where I'm going to make us of a library called as graphical tools all over. So simply saying PM stall graphic You'll I found this all words. So as you can see, the installation is done No, indeed, is all words folder going to create a new folder Karla's model where And instead of this going to create a file called US index torches and here going to export a function Gardas is authenticated on this is going to be a function basically And since we're going to use this function as it is all over middleware in few minutes it will have access to the same argument as we have in the normal results. So I'm going to ignore the parent object as well is going to ignore the arts. Object is well on from the context I would like to fetch female on. I would like to simply remove the logic from here Which is this one on going toe pestered over here in the middle? Well, so here it is going toward the center if the medicinal. But if the email is normal, that means of the police present, then we want to call the next result war. So you can call the result were using the escape functionally deployed by the graphical tools All the package. So let me import the escape from graph Crude is always on here when you simply say done escape. So what this escape will do is it will call the next results. So now let's go to the user door Js file and use this particular is all water middleware with the user cities all over. So first of all, I'm going to inject. The utility card has combined to result from the graph will dissolve word So here gonna say const combined, That is always And I would like to get it from the then afterwards because all words and I would have told so import these authenticated it's all water middleware. So here gonna say const is authenticated on this basically comes from the middleware folder and finally we can use the combined is all over your ability over here. So gonna simply say combined this all work And in the first argument I'm going to provide the is authenticated this a lower middle there And in the second argument, going to provide the user is over and simply going toe close this bracket over here. So that's all you need to do. So as you can see now, the logic off checking the mail is affected away. Insert off the is authenticated middleware, which is going to return the error if the mill is null and if it is normal, we're going toe returned escape on This escape is responsible for calling the next result or which is this one. So I hope you understand now and let's does this instead of the Boza. So let's go to the residence and play the fresh. So let's try to check the log in functionality first. So if I attended as you can see, I'm able to get their token on. If I hit the get usually be without. Ditto. Let's see what happens. So as you can see, it says access denied please talking to continue on Dhere If I passed, the are broken in the authorization and they be around. So let me simply pass it over here. And if I heard this now then as you can see, I'm able to get the response from this over. So that's all we wanted on. We can't reuse this particular middleware in all those result war on which we want to check the authentication and we don't have to write the same re protect logic in each and every results. So I guess that's it for the results really were. And I hope you were able to follow along. And thank you so much for watching this video 28. UPDATING: Get User By Id: Hello, Everyone on in this room. You're going toe Update this. Get user by decree. So little we were passing. The ideas and argument are so this particular Korea's you can see in their type definition . But now we'll use this particular query only for the logged in user. So if the user is logged in, he can see his own retail on. There is no need to pass the idea because we can fetch it from the authentication state. So I'm going to remove this idea From here on, I'm also going to remove the list of users AP as we're not going to implement this now we just implemented for understanding the basics of the graphical. So let me remove this as well, and I will go to the user is always on festival going to remove this user's query and nonsense. We have removed the i d. From the argument there is no need to use this particular argument, so no, simply ignore this one on all of you need to do is tow fired, equated to the Mongols model on guided data and start off this static data that we used to fetch earlier. So going to remove this thing as well. No, he really basically right. D quickly. So when a second use their equal toe await user dot Find one and I'll find using the email so I can make it off the military Over here on. I'm using the six shortcut over here. So this thing is equivalent to this on here and basically, take if the user is not so going to simply take it over here. Andi, if this is no, then this condition will be true. So here gonna say through new on here gonna say, use a north phone and now all bets related on the user from here. And we're also like to make this function Issing because we're using the other key word on , well liked also at the trackage block over here. So I'm gonna catch the error on move all of this. Scored inside off the try block on here. Going to simply console log theater on going toe toe the error so this looks fine on if you have a look at the user type definition, then you will see that here The graph quilt line can also credited task. So if you have a look at here at the bottom. Then you will see the task filled result were and as off notice pointing to the constant file. But we are going to replace this with the task mongers model. And if you're wondering that, why do we need this task Free level result were then we can basically populate the task later. Date out over here using the popular it mattered. So what this popular elementary will do is it will basically take all the task i d. From the user. Data on it is going toe automatically get all the data from the task collection which is a separate collection, and it is able to do so because we have defined the relationship. So if you have a look at the user model over here, then as you can see, the task is basically holding the list off our task. I d. Right. And it is a referencing toe, the task model which is defined over here. So once you use depopulate method and specify the field on which you want to apply depopulate than all the ideas will be replaced by the actual task details such as the name completed user and it is going to be a complete object instead of Justin I. D. So it's similar toe joins we have in sequel so we can popular date over here on. Maybe we won't need the task for level, that's all. What, over here. But there are a couple of desert on days off, populating the data right over here and start off resulting they retained. The free level is over. And I'm going to discuss about this in the dedicated video called US Data Loaders. And we're going to discuss it a little bit later in this course. But it's off now. I'm going to remove this popular thing over here, and we're going to understand the executives in by were using the free level dissolve or over here instead of depopulate. But before removing like me, just quickly show you how can you, especially the field that you want to populate. So here, instead of the populate matter, you have to specify the part and internal depart. You have to space for the feeling which you want to populate on. This is usually the field on which you have defined the relationship. So here, going toe simply said Task And it is going to actually populate this task list off ideas with the actual task object. So there tell you basically do it on. Let me remove this now, since you are not going to use this now, let's focus on the free leveled result were so here going to remove this as we're going to make it off the task mongers model. So let me, first of all, import the model over here. They're gonna say, const. Dusk on this basically comes from database slash models slash task on Dhere. Going to simply say const dusk equals toe, await us don't find. And instead of this fine, I'm going toe basically search on the user level field, which is president. Insert off the task model on going to pass the idea over here that we can fetch it from the parent object And now I can do it under task on going toe wrap everything inside off the dry kids block on would like to move this over here in the try block on going to simply console log the others over here on going toe toward the other on. We'll make this function Issing to make it off the other cured. And now, since we're not using the user and the events constraint report so into the motives from here and yeah, I think this looks good let me see if this let's go to the browser and the fresh on going to remove this idea from here because we are no longer using it. So going to remove this thing on first awful going toe hit the log in IP EI toe. Get the token on Going to pass this joke on the way here. I know if I heard the user Rabia the residency, I get the details off the John. And now let's Fred Logan with some other users. For example, Cabinet the Red Demon Lord. Calm going toe. Log in with Kevin and regimen dot com. Hit this. As you can see, we have there talking for the Kevin User going toe past this particular token over here, going to simply paste this on if I heard this now, then, as you can see, I get big reels off the Kevin on here. I can get more details such as the email. I can also get the task and from the us again Select differences society and the name on. Although you're not having the task, it's off now but still going to simply hit this. So as you can see, we're getting all the details along with the task. So once we implemented task, then we're also going to see their task being populated over here for this particular user . So that is their trip for this particular video on die. I hope you were able to follow along. And thank you so much for watching this video. 29. UPDATING: Create Task Mutation: Hello, everyone on In this video, we're going toe operate. They create task magician. So if you have a look at the type definition instead of the task, then as you can see here is the Cato expedition. And here is the input. So here we were also getting the user idea from the graphical flame. But this time we're not going to do it because the logged in user can create his own task on Since we are having the authentication information about the logged in user, we can fetch the use ready from the database itself. So we don't need this particular thing to be passed by declaimed. So I have basically updating for type for the create task magician. Now, let's go here and going to remove everything from here on. Let me import the task model. So when I said const does according to require, I'm going to get it from the great abyss slash mortals slash tusk on here. Gonna say const thus equal, do new instance off their task model. On inside of this, I'm going to spirit away all the frieze internal dean put object. And that also was the use already in the user feel for visited task is created. So if you have a look at the data base model of the task, then as you can see, we're basically starting these already in the user field instead of the tasks model. So here I can get these ready by fetching the user from your database using the context object, because in the context object, we have the email of the user. So here, going to simply say email over here. And we'll also import the user Modelo here. So gonna said const. User equals two required. I'm gonna get it from databases slash mortals slash user on here. I'll say const user required to of it. User dart, find one on going to pass the email over here on a soon as I get the user going to pass the user dot idea over here. So I hope this makes sense. And I'm also window played. The Izzat indicated Middlebury over here. So let me just inject that. So you're gonna say const is authenticated and I can basically get it from the middle where folder on would like to also importantly, combined is over. So when I say combine it is always and I can get it from the draft. You will resolve hours on Dhere going to use the commanders over. So gonna say, combined these overs and going to pass these authenticators are lower middle better over here and in the second argument would like to have the result over itself on going to simply close this bracket. So I hope this makes sense. So now that we have the task object ready, let's know, implement the same method on their tasks, Owona said, Const resulting square toe Oh, wait. Dusk, Dark sea. This will actually save the task inside of the date of this on What I would like to do is as soon as they task is saved instead of the database, I would like to push this newly created task I d inside off the user. So let me show you. So if you have a look at the US schema So as soon as this new does escalated for the logged in user, I would like to store the newly task I d insert off this task. So here, going to simply say, user door test dark bush and I'm going to push the desert or i d on. This is actually the task. 80 on We have the user object available over here and finally going to call the overweight user dot sale. So there. So I need to go on finally going to return the newly greater task back to the draft. Girls lined on. We like to put everything inside of the crack. It's block on going toe console log, the error on also going toe, I told the other, and we like to move everything from here inside off the try block. So yeah, I think we're going to go. Let me save this lead school to the browser Onda fresh. So I think there is some other let's take on the terminal. It says it is only valued in servicing function. So many toe declare this function as you think. Save this again. Let's go to the browser the fresh again. Now let's go to their task A pier on going to remove this existing queries from here as we are not using it on going to use this particular mutation, which escape task on it is basically saying that the user Eddie's unknown feel so going to remove this since you have operated this schema for the same and yeah, I think this looks good like my head, there's no let's see what happens. So it says access tonight. Please log in to continue on. This is expected because we haven't provided the extra beheaders. So simply copy the herders from here on the street over here. And now if I heard this then as agency, we have the newly task created. Now let's go to the database and check. So here I'm going to simply the fresh face. Then, as you can see, we have their task collection over here. And as you can see here we have the newly created task which has the name of the bullion status and the user ready for With this task escalated on, we need to check one more thing which you have done over here is toe push this particular task 80 toe the user Tasca. So this user is basically created for, I think, excluded for the Kevin. So let's go to the cabin and check if this 3416 is pushed. So I will go to the your collection and let me refresh on open this Kevin over here, then, as you can see instead of the task. Very for the Kevin, we have the 3416 task 80 that is pushed over here on Lex. Frederick does this with another user. So, for example, if I district for the John So let me, first of all, get the token for the John. I'm going to assembly corporatists on Mr Door here on, uh, what I'm gonna do is going to name the task as, for example, shopping. Hit this. As you can see, this created nerd school illiterate, jobless goto their task, their fresh that is against you. Here it is created shopping. Here is the user i D, which is triple toe see with which is the already off the John. Let's go to the John Refresh. And if I view the John record than his agency, their task is being pushed with the newly greater task ready. And one last thing that I would like to do is tow. Add the created at field and the updated feel inside off the task type definition. So let me just go to the task definition on here. Going toe articulated that and it will be off type the custom decks killer on. Also, the update on this will also be off type custom dates killer. So I was there except for this particular video and I hope you were able to follow along. And thank you so much for watching this video. 30. UPDATING: List Task and Get Task By Id: Hello, everyone on in this video, we're going to implement list task worry on get asked by ID Equity Now, before writing the query results for the same, I would like to also add the logged in user ready in turn off the context because since most of our resolve wars, we'll need the logged in user i d to perform various operation. So instead, off fetching these ready from the database using the logged in user email in most of the result would lead simply, ideally instead of the context, and it will be available to all the result wars. So let's go to the context now here. First of all, I'm going to say the quest dark love been used already and answered eternal. Now here I'm going to quit the user model. So here gonna require the user model. So when I said const user required to require and I can get it from the w slash mortals slash user and now heroes. A const user equals to await user dark. Fine one on here. I'll basically past email on we can't get it from payload doors email on Dhere. We will have the information regarding the users. So here we can say requests are locked in is ready equals to the user dot idea that certain they're solving it to do on. Let's go to this other world or two years on Dhere going toe our duty in sort of the context. So here gonna say Logan is already he calls to request start logging is ready. So you, now that we have this ready, we have access to the logging is ready in each and every result work. Now let's posted for that with writing the list off Tasked with the word. Now both of this query can only be performed by the logged in user. So let's add a is not indicated. There is a lot of middle where the boat off this credit. So going to simply copies on going toe pestered over here. Let me simply closed the record over here on going to do the same over here itself. Let me close the Beckert away here. No, First of all, let's walk on the list off task is always now here. The not only want to execute this result work on leaving these Juries authenticated, but we want to return only those task Vitor created by the user. So for that we will need the locked in is ready. So here I can get that from the context object. So going to ignore the parent object Going to ignore the powers object is well and from the context object I can be structured the love being used already that we just said that interrupt the context And now we can use this 30 took at the all the tasks that are associated with the logged in user So we're going to simply say, const thus it will do a weight task don't find And I can basically find it on the user field because this is where the idea of the user is stored and I can basically positive us lobbying is ready. So there is quite simple. Let's make it off the easing functional here. Since you're using the r word on, let me at the wreckage block as well. So in case off any other going toe, simply console, log the error on going toward the other. And now I would like to move this statement over here. No, here will simply returned a list off us. That's all we need to do so. I think this particular credit is ready. Now let's work on the get tasked by I d. Quit e now. Instead of this, we need to take care of two things. We have taken care off the force thing, which is to check whether the user is authenticated or not. But when it also if the user who is requesting the details of the task is actually the creator off that particular task, for example, it was John created a particular task, and let's take Kevin try to exist the John task. He should not be able to viewed. So we need to check better the use ready on their task. Is it willing to? The locked in is ready, and we need to do this for various of their operations as well, such as updating a task or believing the task. So let's suppose there, John and Kevin both somehow has access to their each other task I D. But we should restrict them, are to relate each other task because they should only be able to delete their own task. So we need to somehow check the owner of the task. So for that I'm going to create a middleware because we are going to use this particular logic on areas of the operation as well. That is a delicate task. Are operating the task. So here in the middle, where I'm going to create a function called as ISP Ascona so gonna say model dot exports dot is task owner on this is going to be a result formally liver function. And here in there is a lot of money that we have the same arguments available as we have on the normal to solve would function so far. So we're going to ignore dependent object. Then from the are subject, I'm going toe fights the idea that the user will provide for which he wants to get the detail on. Finally, from the context object, I can get the not been used already and now we can basically check if the local newser is the owner of the task. So here, going toe festival import the task model someone as a const. Task equals two required and I can get it from the database slash models slash task on here . I can say const dusk equals store rate. Thus dart, find by 80 and I'll basically passed their task ready over here. And I'm also going to make this function. You think on here? What I'm gonna do is I'm going to simply check if the task is not found that once. If their task is not that I can simply it for the other. So when I said through a new era on going to pass the error message as dust, not phone and now we can take the owner of the task. So here, I'm gonna say and safe tusk door to user is not equal to the logged in is ready. Then we know that he's not deal not so not simply throw the other over here. I'm going to see the message as not or traced as lascuna. And since the task that user will be in an actual objectivity and love being is ready the string. So let's convert this object idea to string using the two string matter. So there are competition works fine. And if all of this condition fails, then going to simply return the escape which is going to call the next result now will use this particular Middlebury instead of the task query. So first of all, let me required this middleware. So when I say is Toscana and I think I can also add the wreckage block over here. So let me quickly add this on going to move everything from here in sort of the tribe block on, going to simply toward the other and also going toe console Log theater on Finally, I'm going to use This is task owner is all ordinarily where Over here. So I hope this makes sense now we can finally fed steer task information from here. So when I said const does equals to the over, it does start find by 80 on going to pass the idea over here that we can get from the art object And here going to simply great Dundee task that's it. Going to wear the brackets block. Let me move this thing over here. I'm going to console on the other and would like go toward the other as well. So when I say throw, that's it. So now let's go to the brother in test and like assembly. Refresh this. I think there is some other Let me check instead of your terminal eso the it says of it is only valid in Saturday's in function on 22 line. So let's go with 22. Okay, so we need to make this function. I think so. Let me see this large school with browser and refresh again. So I think this team is working. Fine. No, let me simply Dundee Equity on I lean the operation is get our task and would like to fetch the list off Task first on, we want to get the i. D. We want to get the name. We want to get the complete its status as well. So let me get this now so it says access to United Place logging to continue. So let's grab their tokcan for a particular user. So I would like to grab it for the John. Let me hit this log in a p A. We have this talking over here. Going to copy this on would like to add the alteration heard over here. So gonna sell a transition well past the broken inside of the Beerer. And now if I had to get on task then as you can see, we got all the does that we have created. No. Let's add more task and test. For example, if I say complete project if I had this as a concert task is created. If I don't get on a task, as you can see, a gardenia liberated us and there is one more thing I would like to show. Use that. For example, if I create the task for the Kevin on, then if I basically asked for the list off task, we should not get the task which is created by the cave in. So let's test it now. So, for example, if I took one for the Kevin hit, this hit is due to open for the Kevin copies on Going toe pestered or here. First of all, let me hit this Guettel Dusk Then, as you can see, we have some different us for the giving. Now, for example, if I could hear the task for the given such as, ah, work out had this hesitancy tasks created. If I don't get all task, then we only get the task that is created by the cabin itself. Okay, on if I change the talking back to John and if I had this pregnancy, we get the task list, which are only associate. Ditto bitch on no natural surpassed the get singletons body. So here. Gonna see equity get those body on instead of this would like to run the task query on for the i. D. I would like to pass the ideas. For example, this one Let me simply copy this festered over here. And I would like to fetch a single task name completed status. And as you can see, I called Dick Daley as soon as I hate it, and I can ask for the creator that a break directly as well. This residency. I got the results. Let me try for someone already. For example, this one shopping. Let me have this. Now, as you can see, I'm getting this knowledge for to fetch the hospital, which is created by the Kevin. But we're facing it using the John credential. So let me go on. I'm going to grab the task i d, which basically belongs to the Kevin. So let me simply copies on if I try to hit this. Now, let's see what delegate? So if I get this, as you can see, it says not or tries is Toscana because Johnny is trying to access the Kevin task detail. So this check is also working fine. And there is one more thing with this. Remaining is to simply I had the user free level dissolved because, as you can see currently, we cannot fetch the user level information. So, as you can see, it is not working because we haven't implemented the free level results for the task type. So let's go to court, weighs on, glared the bottom and here going to remove this on here, we will have access to the parent object. It will have access to the test object on foretell CoreLogic. Let me simply grab it from the task here on going toe. Hastert, over here on here, built into the model from task to user, will get the idea from parent objects of another parent dot users because the user feel on the task. Object is actually holding these already. Let me change the name over here. Ongoing. Putin's over here as well. So I think this looks good. Let's go. But the browser tender fresh. So I think there is some error. Okay, I got it. We need to make this function, you think? See if this let's go to the browser and fresh again on Let me try to hurt this now that as you can see, we can get these. Their information is well so I can ask for the email of the user who is associated to this particular task. I can ask for other fields as well, such as the name of the user and everything related to the user. And the same goes with the ghettos by ideas. Well, I can ask the user information here is well so for example, if I asked for the email and hit this now So let me get the correct austerity for which the John is the creator. So going to hit this again? For example, if I get this popularity on the street over here and if I hit this, then as you can see, I can grab the user information as well. And again, if you're wondering that, why did we need the full level dissolve our when we can basically populate the use a level information right here using the populated mattered on providing the field which is going to populate, such as the user itself. So again, as I said, I'm going to discuss about this in the Data Loaders video. It will have a look upon later down the course, but it's off now. Going doesn't play. Remove this on. We'll keep different. Level is over and I think we can improve on more thing. So, for example, if user since the task ready which is not divided objectivity, then let's see what kind of messages returned by this hour. So let's go to the closer and, for example, if I saying any rent a mighty which is not a valid objectivity. And if I hit this now the nets again, Staved says. Cast toe objectively feel for the value. So this area is basically thrown by the mongo db. So it will be better if we can hide this must detail on just implicit that the idea of it is signed by the graphical client is invalid. So let's do it now. So I'll basically goto the result of middleware on Dhere. We can basically check whether the ideas of valued object idea or not, and you can check it using the mongoose package. So instead of taking this over here, I'm going to create your ability or the helper method which we can use in. And it is all word nor decide this place. So here in there that I was holding We have a util file. So instead of this utility, I'm going to create another utility. Parlous is valued objectivity. So when I say model Lord Export Dart is valued objectivity on this is going to be a function on here. We can simply return the mongoose door type Dark object really is valid. And you could basically pass the i d. So we'll pass it as a parameter over here on going to simply pass it over here. And it is going to simply it on our bullion value, true or false, Whether the object that is where you don't know, Phillips used this particular utility method over here in there is always so let me import this utility matter. So gonna said const, he is valued object. I d and I can basically get it from the data on going to the utility folder not basically used this matter over here. So when I say if his village object ready on going to past 30 and if this Retton's falls. Then I'm going toe toward the other, gonna say through new on going to pass the message as invalid Dallas Katie. So I hope this makes sense. So instead of sending the user of this kind of message cost to object, I d feel it will be aware that if we can send this message So let me say it this on. Let's hit this again. As you can see, we have the proper message. And no, if I passed the correct i d. Let me just copies festered over here and heard this as against We're getting there. So is there sit for this particular video And I hope you were able to follow along and thank you so much for watching this video. 31. Update/Modify Task Mutation: Hello. Everyone on in this world of you're going to implement the update task imitation. So let's for civil update the schema. Then we will implement the soul words. So I'll go to the task. George s on here. Ollie, create another magician called us Update Task. And here we last for the ICTY, which will be noncallable. And the rest of the field can be sent instead of the input object. So going to create another input type car less update task input on it will be non a level Isabel and ultimately this going toe to toe on the task itself. Now let's create the update US input tape. So here gonna say input object asking foot on Dhere The user concerned fields such as name which will be off type string on the completed which will be off type bullion and that's eliminated on. We're keeping both off this field as in a little bit because users would be allowed to update any of different individually. So now let's go to the result were on here going to create another is over. Cordes, update Dusk on going to pass The commanders all words on here going to pass these authenticated middle as well as the task owner middleware on. Then we will have the result or function. So here, inside of these olive function, we will let the task I d and the input object so we can get it from the argument Objects were going to ignore the parent object on going to restructure and get the I. D and the input object from the argument object on Dhere going toe Simply say const dusk equals toe of it Task dart find by i d and update. So I'm going to use this method because this not only update the record but also returns the all the feels off their to guard hands I have chosen this matter. There are elements of level is well for operating So as of now here going to pass the I d. Then you have to pass the fields that you want to update. So I'm going toe spread over from the input object on at last In the extra options I'm going to pass option called as new and will specify Devalue s true. So what this will do is it will give me the latest operated record that is what happens is that whenever you update any off the field and if you don't specify this, then it is going to return you the Oldfield on. If you're proud of fat, second time, then it will give you the update field. But if you pass this particular optional here than it will right over, give you the upgraded fields. So now you're going to simply have done their task on going toe date, right? Gets block over here on for throwing on concern logging. Going to copy this ongoing toe pestered over here on going to move all of this interview, Try block and I think they're going to go. Our mutation is ready. So let's go to Lou Groza on the flesh. So no, here, going to run another mutation called as object us. So gonna say mutation Update dusk and here are basically ask for the great tons. And even if you check the dogs, then you will see that a new addition will show which is after task over here, and you can get all the information about the same over here. I mean it past the idea Over here on let me copy the idea from here on pestered over here and then instead of the input on it, to pass the fields that I want to update. So let's suppose that I want toe update the completed field and he basically said, is true on In response, let me ask for the i d Let mass with the name Litmus was completed, and yet this looks good on Let me hit this. Now then, as a considered say is true. Let me basically try to get all the task at this. The Nez agency, the completed Streeters, they said, True. And let's read update both defense. So here I'll pass the name as, for example, shopping online on if I heard this. Now, as you can see, the name is also operated and little to try. Someone doesn't know where we positive wrong. Ready? Let's see what happens, it says in Willy. Task ready on defied fight toe basically passed their task ready off the kevin. So let me just go to the database. The task ready off the cabin with his new task. Let me copies go over here pasted over here. And if I try to update the Kevin tasked with the dawn credential. Let's see what happens. So it is not authorised as a Toscana. So there's no scored on the young guys. That's it for this particular video. And I hope you were able to follow along. And thank you so much for watching this video. 32. Delete Task Mutation: Hello, everyone on in this room you're going to implement the delicate task magician. So that's update the daughter skim over here fistful and here going to add the late task and we last for i d. As an argument which will be known. A label on this is going to return the dusk object. No, let's go to the result on Dhere in sort of the mutation object going toward another magician called as deal it dusk and again we'll use the combined is always toe. There is a lot of middle where so you're going to add the results indicated we'll also at the past corner middleware and at last we will have the result of function for this particular magician on we will lead the task 80 inside of this particular is over. So I'm going to get it from the argument object. So going to restructure the argument object and get the idea over here on heroes Seconds does equals toe a bit Task dog find by idea and delete on going to pass. The idea we're here on this matter is not only going to relate the task, but also going to return you the fields that were there for the military task. And now we need to do one more thing, which is toe delete this particular task from the user's masquerade. So if you have a look at the data base, then as you can see 40 John, it has to cascading instead of their task. Carry on as soon as either off this task is diluted. We should remove this task idea from here. Also big because if we don't delete it, then we will have an biggest information in sort of our database. So let's add the logic for the same. So here going to say Wait user Dart update one on. First of all, I would like to find the user using the underscore I d feel so here will specify the Andhra security on here I can pass the logged in is already which I can get from the context object. So going to get it from here next. We want to pull out this particular task ready from the task. So for that, I'm going to make it off the pool operator and here l specified Ifill from which we want to pull over the I d on now financial space with the i d that we want to pull out with this past 40. So I hope this makes sense. That's what we're searching the user using. The loading is ready, and we're pulling out their task. Got I d from the task. And finally, I'm going to simply return their task on would like to wrap everything in sort of the frigates block. So when I should try catch on, going to move everything inside over here in the try block and here gonna say console dark log and would I goto The others are gonna said weather. So let me say this. Let's go to the brother and the fresh. So if you have a look at the dogs that, as you can see, we have new mutation over here, which is delay task. Now, let's first of all, Grundy get all task equity to actually get the list off Task I d. So that if we can perform their deal, it us using any off this idea. So here, going toe right. The mutations of Assam rotation operation name has the lit task and will specialty mutation as direct task. And here I need to pass the idea right on from this or what it wants. I can ask for the i. D name and the completed Streeter's off the tusk that is deleted. Now, let's suppose that we want to relate this idea which is shopping online. So going to simply pestered over here. And if I heard enter and as you can see, we got the response. If I don't get all task now, then as you can see, we only have one I d left. No lurks taken, Cheryl database. So if I basically the fresh then exigency Now John only has one element in the task of let me just show you which is this one. And if I go to the task on basically fresh the next vacancy, the shopping online is deleted from here. And if I tried toe, delete this complete project as well. So let me just delete this as well. And if I hit this as you can see the result of the litter, if I don't get all task, we get em teary. Let scored the database. That's fresh it over here. As you can see, their task is related. Let's go to the user. The fresh Now the task is holding zero element. So this is working perfectly fine on that's it for this particular video. I hope you were able to follow along. And thank you so much for watching this for you. 33. Offset Limit Pagination ( Task List ): Hello, everyone on in this video, we're going to implement the officer limit presentation. Now, I have already created some off the task for the user, John. And as you can see inside out the database, we have a bunch off task and I have created this so they're begin by their understanding imagination. So the way pagination works is that you have an officer and you have a limit on this. Absurd is generate, um, as skip intern of the Mongo DB. In other database perspective, we just referred it as off. Certainly. So off sort of basically defines the in the more off record you want. Toe skip on limit. Basically defense in the mud off records that you want for a page. So it's quite simple. So let's implement it now. So I'll first will go to their type definition on here. Inside of the task, users can basically send two values. The 1st 1 escape on this will be off. Typing teacher on second will be off type limit on. It is going to be in digital as well. Now let's go to the task is over on Dhere going toe, grab the skip and the limit value from the argument Object. So here I can say escape Andi limit. No, If this keeping limit is not part, I'm going to define a default value. So I really find their deformed value for the escape at zero on for the limit. I'll define, for example, 10 Now, over here. First of all, I'll sort the accord by the I. D. In the descending order. So you're gonna Sadat sort on a space where they feel that I want to start with with his underscore 80. Then here I'll specify the minus one which dinner orders that we weren't in there descending order. And then he runs a dot skip as escape on going to pass the limit instead of the limit function. So I hope this makes sense. So let me say this. Now let's go to the browser. Let me refresh. And if I hear the for example getting taskers off now, it worked really fine because they skip and the limited will your optional. Now let's work with escape in the limit, will you? So here you under specified the skip value at zero and will specify the limit as five Let my head this. As you can see, record the five records. And if I specify, the escape has Five and LTD's five. If I hit this, then as you can see, we called diesel from us 5 to 1. Sort of a donation is working fine, but there are some issues with the officer limited imagination. So basically there are police, and one day it is the 4th 1 Is that human doctor? Duplicate records. If your list is abraded quite frequently on the second visit, one date is performance. So we are going to implement another approach, which is called us coarser Bates imagination. And first of all, we're going to combat how the offset Lim works were says, How did car service work? Then we will implement the car service pagination in the next video on for this video. That's it. And I hope you were able to follow along. And thank you so much for watching this video 34. Offset limit Pagination Vs Cursor Based Pagination: Hello, everyone on In this video, we are going toe. Compare the dough. Pagination approaches the force. One is the off certain limit. Who are, says the car service pagination on. We're going to see how the car service Big nation solves the problem that the officer climate has. So let's move on. So let's suppose there initially you have 10 records instead of the table on your showing. Five records probate. So on debate one just before the officer to zero. So you get the 1st 5 items so you get from item turned to six. On the second page, you get 5 to 1. So this is how you're displaying the items. No Lord supposed that your list is a bleeding quite frequently right. So what might happen is that let's say you were on the page one on you were able to see the item Trento sex. And while you were on the page 15 new records got added. Insert off the table. So now if you never get to the page two on dure specifying the value is offset five and limit five because you want to show the consistent five desert on every beach so you will get the item 10 to 6 again. The reason is that since this five new records are headed on new, specifically off surface five. So this five records are skipped on you again see the item 10 to 6. So the page to records are exactly same in the page one as well. So this is the problem off duplicate records in gets off off certain limit pagination on This usually happens when your list is frequently updated. So let's see words the better approach for the same. And I'm going to show this duplicate the core problem. Live into our application. But it's off. No, let's see the ultimate approach, which is considerably spirit nation. No. Here you basically have a cursor on. It basically points to a record deal which the dice fast. So, for example, you were on the page one and you ask for the 1st 5 records. So these are basically gave you the force where the court from 10 to 6. So the last record that this fast is the item six. So now the cursor basically points to the item six. As you can see over here on because there is nothing but a unique identifier that points to a particular item inside off the table, such as the idea off the item. So you get the list of items. But server also returns you the and cursor, right? So what you can do is you can use this and cursor toe created the next set off records. No, When you ask for the beach toe item, the server already knows that the anchors there was Item six on. I have to fetch the next five record. So it will basically give you that. I don't fight for 3 to 1. So as you can see now, they duplicate problem is solved on even know the five new items were added while you were on the page one. Still, you are getting the appropriate result. So this is how the are sort of bs pagination work. And most of the companies, for example, Facebook, instagram, twitter. All of these companies have a pH on. All of these babies are implementing the car service pagination, so you understand how big off a problem it becomes When your list is operated quite frequently, you will end up with the duplicated cards in case off offset limit imagination. And as we discuss before there is another desert one. Pitch off the officer limit pagination over the girls are based detonation on bitches performance. So in the officer limit presentation that always has to scan from the zeroth item on scan all over the off certain item. But in case off the cursor based imagination that it others can directly go to that particular item where your car service pointing toe confessed the next set of items so this comparatively faster as compared to the off supplement. So now let's push it further with the life demonstration off the duplicate records. So, as you can see, here we are in, start off our application Ondas off. No, I'm going to remove the skip and the limit value from here and going to simply hit the task ap I get all the records so they can see. Initially, we have tended cards. Now, if I basically first of all, specify the skip value as zero on limit values, for example five. And if I hit this, I get the item timeto six. So these are five the guards and next for the page to specified escape as five on limit as fight. And if I heard this, then I get the result as past five to ask one, right? No. Let's suppose that while I was on the page 15 new record scored added somehow. So let's fry to add those record on. Let's see when we never get to the page, toward happens. So, for example, here in the clear task magician, I'm going toe five near records, for example. Task 11 asked. Well, does 13 does 14 and dusk? 15. No, I'll go over here. Andi, basically space. Why? They skipped the US five and the limit is five on initially, people getting the record from 10 to 6. And if I hit this that residency again, I got the record 10 to 6 on dares to duplicate record problem. And if you have a look at the data base, refresh then, As you can see, we actually have 15 items in several database. So this is the problem that you have on. But we're going to solve this with the carcela based detonation in the next video. But I just wantedto give you a little demonstration, so I hope you will. It will do for no long and thank you so much for watching this video 35. Cursor Based Pagination ( Task List ): Hello. Everyone on in this radio via going to implement the Kurtzer base pagination. But before posting for that, I would like to remove some of the unused imports such as the your i d on this constant from here and also going to delete this constant folder as we're not using it. So as we know that in the car service pagination we do have a coarser. So instead of skip, we last for the cursor from declined. So let's update the type definition. So I go over here on instead of Skip, I really find the cars are over here on this will be off type string on. Since this is optionally, it can be no level now, Here are basically received this car set over here. Now we can remove the escape from here because it is no longer required. Now I'm going to defend this particular query are sort off the find function so that I can dynamically add or remove the data. So here, first of all, I'm gonna say const career equals to this. So, of course, are no matter what we want to fetch on Lee the task which are associated to the logged in User, Now we'll take into custody is send from declaimed on We're dynamically prepared equity So here, going to apply the f check if because there is found And usually what will happen is that when the client is requesting for the first time, it will only specify the limit. It won't have access to the council but when we returned the data, it can have access to the concert and pass it over here. So we need to dynamically prepared the query if the car service ST so as we know that because there is a unique identifiers such as the I d or the creation date off dark particular record. But I would like to choose the underscore I d feel over here because the underscore idea field is not only unique, but it is also indexed on car. Sir, Pagination works best if your field is indexed. But you can do that or feel as well such as the great date. Andi even index it. But we're going to use the underscore different as a cursor over here on. I'm going to credit the underscore I different because that will be our culture. And now here we love like the condition. Now, before writing the logical here, let me just explain your examples and ideas so that you can understand. Clearly no other supposed that initially the user specified the limiters five. So we're going to give them the five year diss records. And let's suppose that we have 15 records in the table. So we are going toe return the records from item 15 item 11. So these are five records on what the graph decline will do is it will pick up the I. D off the last record that it has received, which is the task 11 or the item 11. So it is going to pick up their diary and pass it as a culture. So now, on the next request of and the cursory sent, we want to fetch all the records whose idea is less than the cursor. So for that, I'm going to make it off the less than operator on. I'm going to specify the value Esseker, sir, because we want to find the values which are less than the castle. So I hope this makes sense. And finally, I'm going to specify the square you over here. So instead of this hard cored it, I'm going to pass the query object over here, so I hope this makes sense. Now let's go to the browser in test. So let me see if this let's go to the browser on the fresh Now let's initially specified millimeters five. No, If I had this, then as you can see, we got the five records. No, If I passed the i d off the last fetched record, which is Pasch 11 and I'll part it as a car seat over here on. If I specify this now, if I hit this, then as you can simply get the next five record, that is from task 10 to 6 95 Take this. I d on base Trudeau here and hit this again. Then, as you can see, we get the task five to us one. So our cursor imagination is working Fine. But we can improve this more by providing some maternity information such as the next page Concert on better than expected is president or not? Because of their ways, client has to find out the last record pick up the I D on special vehicles are over here. And what if tomorrow be teens the concert for my deed to the date. So your client apple break. Right. So for that, we need to pass a meta data information. So, Father, that will be updating the schema. So let's goto The classics came over here. Now instead, off are directly returning the ari off task. I'm going toe to find a new type Corliss Task freed on This will be known the level now going to defend this object type over here. So gonna say type Ask Fred. Andi here we will First of all, have the task fit as a key on this is actually going to return the list of tasks. And we will also have another key called a speeding forward. Here on this page in four will be another object tape that we're going to define soon on. This will be non a level. So let me define this object type, which is spacing for on page in for Bill, actually who live a loose such as next Page Carson. So they're Train doesn't have to face the last record. And Fred's 30. The next space coaster will exactly hold the cursor that declines know to pick up on, just simply pass it as a culture. So this will be off type string. And then we'll also have the has next speech, which will be off like bullion. And it will simply specify that better living next pages, president or not. So now let's go over here in the result and modify our response. No, here we need to detect whether the next page exists or not. And we can only do this if we simply fed one more record than this place for limits. So let's suppose that Klein sends the limit as 10. But what we actually do we actually 1st 11 records from the table. So if the number of record fetched, which is task is greater than the limit, that means that more recorder present that means has next page becomes true. And if this is not the case, this means that the next place doesn't exist, are normal record exists and they specified limit. So here in the limit, I'm going to fetch and extracted card. And here, when does embracing. Const has next page, and I can specify this. As dusk dot land is greater than limit So this is going to basically return the bullion on if there are more records than this were true on, if the desert island is less than the limit, that and it will be false. So this is, however, detect whether the next place exists or not. But now, since we have fetched and extra item from the database, we also need to remove it. And instead of just moving directly, we need to remove it on some condition. So there are two scenarios. Again, if the next pitch exist, then we need to slice out the last item from the Tasker because that's an extra one that we've fetched from the AWS. But if the next pitch doesn't exist, that means if the task list is less than the limit, let's say the limit was 10. But even after adding one more, we just got eight records from the database. That means that there is no need to remove the last item since the result is less than the limit. So here we need to slice out the last item, which depends on the has next pitch. So now I'm going to re ascended. List off task on the basis off has next pitch but curious. And I need to make this light, otherwise it won't let me do so. So here I can say if the next place exist, then simply slice out the last item. So here I am going to make it off the slice matter on here. You can specify the starting index and the ending index. And if you want to remove the last item, you can specify the ending index as negative. It is going to slice out the last item on going to return your Nuri. So here going to say, starting in Lex's it'll and the ending index as minus one on If this is not the case, that means if they has next pit is false, then simply going to return daily stuffed us because in that case, we don't need to slice out anything. I hope this makes sense. So now we have all the brutality except the next pitch closer on. We're going toe. Just simply access the next place closer by accessing the last item off the tasker on. We'll get the idea from there. So it's quite simple, But first of all, let me properly returned editor in the former. That is expected. So the first thing that is expected is the task food on for the task food. I'm going to return the task over here. Next minute to provide deep is in four. And instead of the page in four when it took over two things. The 1st 1 is the next pitch car, sir. And I can get the next pitch cursor on the business off some condition again. I can hear Check it has next exist. Then I can get Dean expects closer by accessing the last item I d so gonna say task off dusk dot Lend minus one dart i d. And if then expect is not found, Then there is no sense to send the next best closer. So that gets going to specify. Now, over here and for the has next page is going to pass this variable over here. And remember that testing is a quinto this. I'm using the year six shortcut over here. So if your key name and devalue Neymar seem, you can simply specify it like this in charge. So let me say this. Let's go to the browser and the fresh No, here. I'm going to ask for the ask food and inside every task for it. I can ask for the i d. I can ask for the name on. I can also ask for the page in four on Beijing food can have next which cursor and the has next pitch Boolean variable as well So didn't identify these. And we can also remove this curse off from here because we're going to use it from the next place cursor. Let me hit this now. So his agency initial even, especially the limiters five. I got the five records and also got some metadata information such as the next pitch cursor and they has next pitch on it is said to is true that we take this cursor on simply pestered over here. Onda hit this again. Then we get I don't Time to six. Let me copies and special here Hit this again I get item 5 to 1. Andi has next pitch becomes false now because there are no more records and then expect cars are also becomes no presidency. How easy it is for declined to simply pick up the next place cursor from the patient for and pass it as an argument to work ready. And there is one more thing that we can do is to hide the implementation, retail off the next pitch closer. So let me show you. So currently we are basically sending the next place closer as it is that wins. Whatever the feeling, we're choosing for our car severe, simply passing its value as it is. So if tomorrow if you change your concert of from underscore I defeated so let's suppose created at failed, which is the date then you will say they'd over here on this will be sent back to declined this implementation riddled should be heard and from declined client just need toe have access to a string on He just need to simply pass this spring without knowing behind the scene waters chosen as a closer. So for that we can pass This really was a base 64 string and it is also recommended in the car service presentation that your next pitch culture should be or pick string. That means the middle should be hidden from the client And this thing is also specified on the graph girl documentation. So if you basically search for graphic UAL pagination Then you will see that over here it is a specified died. Let me show you a Zaken. See, it says that as a reminder that the carcela topic on therefore might should not be relied upon. We suggest base 64 including them. So we are going tobe a 64 in court, the next precursors so that the actual value of the car so it is not directly visible to decline and there is altered wanted on this riverside if you make your car sort as base 64 string So if you do so, then you don't have to organ in again. Teens did die inside of the schema. So let's suppose that if you migrate from I d toe created that field, then you don't have to teens their type off the cursor from spring to date inside off your type divination. So if you make your cuts up Bay 64 it will always going to stay spring and you don't have to tease the type definition on this other side. So let's do it now, so I'll go to the core base on I'll declare helper function inside of the helper folder. So going to create an extra Jay's follow here on here, going to declare to function, forced to contort the String Tau Bay 64 2nd book. And what the basics before back to this string. So here gonna say model Lord exports start string Kobe 64 on this is going to be a function on. It is going to accept the data that we want to convert on here. Gonna say before I got from will positively it over here on gonna call the to string method on well specified the base 64 according over here on going to declare another function called as base 64. So string, which is going to reverse this process, gonna say base 64 go string. We'll get the data on here gonna say before dot from data and here going to pass the basic supporting the second argument on Dhere. Go No, simply say pull String on here. Well specified E asking. So I hope this makes sense. Now let's use this function inside of the task result were so first of all, I'm going to import, but off this function. So here, going to say Const and I would like to require it from the help Put a folder on. Word I warned is spring Kobe 64 on basics to forego String on Now, at the time off returning the desert, I would like to simply wrap this idea inside off string Kobe 64 because we want to return the 64th string. But at the time when we received, I'm going to simply convert the basics to four back to the string on good perspective, I think are set over here. So I hope this makes sense. Let's go to the browser fresh. And if I heard the get cold escapee, the nest agency, this is the kind of value that we get now. No matter what you implement behind the scene, you will always get a base 64 OPEC string back to declaimed on. If we specify this concert over here and if I heard this then as you can see, everything looks fine. We get time to six and if I simply big this pistol here, hit this as you can see, we get the next records. No, I'm going to run the same scenario that we had in case off officer limit pagination to demonstrate to you that they duplicate record Problem is sold in gets off the course RBS pagination. So let me remove this girl surfers to fall on that We heard this so initially we have this 15 to 11 records Noto make the exact same scenario that we had in case of absurd limit pagination. I would like to remove this five records and build dynamically at this five record while we were on the page one on. That's what we did in case off Selim it and let me do it here also. So I'll go to the root of this on going to remove this five records from here. Legman Day like this, the fresh go over here and hit this again. So now the latest five record that we have is from the task pen, but it has six now Why you were on the page one. Let's add fight more records behind the scene on Let's see if we never get to the page to using the cursor, what results we get. So I'm just going to use this castle on Bay Street over here. Although I'm not going to hit the bear now but just going toe. Keep the culture for the reference. And now let's assume that we are on the page one and five New record guard added behind us in. So let's go over here and added So here gonna say task 11 12 Just hurting does 14 and dust 15. Let's take insert all DWS Let me refresh. As you can see, we have this five new records now. No, If I basically hit this ghetto task a pia with the culture that we had previously So let me hear this then, As you can see, we got the task five Task one because this car, sir, was pointing to the top six. So even though the five new records court added just because we had the pointer we got the proper result on we did not God, the reputed result that we used to hide in the officer limit imagination. So you guys that said for the car sideways, pagination And I hope you were able to follow along. And thank you so much for watching this video 36. Data Loaders - What and Why: Hello, everyone on in this video, we're going to understand water Day totals on by Do we used little orders? But first of all, let's have a look at the current situation in the telegraph to Libya's standing, so that if we can clearly understand the need for the data loggers So currently we have implemented thief a level result walls on in the previous video I told you that why are implementing the fairly level dissolve wars on why we're not quit everything inside over here in the task result war by aggregating the data from multiple collection using the populate method. So this is equivalent to the joints in sequel. So currently this is our implementation is done. First of all, we find out all their task and for each task, we found out the user information on this field level result on lead ins when the user is sequestered. If the user is not in question, this is not going to run. Now let's suppose that what if we would have implemented everything instead of the task where it is all over without the fear level is over. So we would have to populate everything over here right. So here we are asking with a list of task and we also need the user. So we have populated the user field that this president, instead of the task model way to basically popular it's all laid it off from the user collection. So this is the kind of data 30 bed. So this particular logic look scored for this query. But what if users simply asked for the dark sky D name and completed? So if you populate everything over here, then essentially you are forfeiting their tough on the database because use the level information is not even required are requested by the graphical Klink. So if you have a look at the field level result over this thing used to only run when the graphical client actually ask for it If the client doesn't ask what it this will level this over isn't going to run. But in case off populating everything over here, this is always going to run and you will always have the user information we're here on. You are essentially over fetching the data. Now there is one more disadvantage off populating everything over here on. It's basically deep, very complication So let's suppose that the client basically us we're very deep Nestor Cory , because the graphic claimed has dip our toe query as depressed, they warned. So they're supposed that they asked for the list of towns. Then there's for the user level information electricals that again asked for the list off us. And if no deal is off first, let's suppose that we heard another collection called Exposed so they would have requested the post over here, right? So we have to do this nest rate population by now. As off now, I have hard coded this part field right, But in real level scenario, you have to dynamically detect which are the fields or the model that you want to populate . Eso you have 1/4 argument in. There is a lot function called as it is all over in four. So using that, you can actually find out What are the fields that have been requested particular after declined. But again, you will have to map every field and detect whether that field is a normal field in sort of a collection or whether it's a separate collection and accordingly, the inimitably detect the depth off the populate. And there can be possibility that whatever relational data the graphical client is asking, there might be no relation in the database. So there is so much complication. If you do everything at one place because as you're ready and your scheme as goes into my people object types or multiple collection in for talk about in terms off databases, you will face a lot of issue with the deep equities. So this is not a good idea to populate everything over here because it will make things extremely complicated. So does it mean that the free level result where is there a limit solution? And it's a good solution and it's official solution. The answer is no. There are lizard one digits with the field level result also. So let's see word out those desert one bitches. So the because they said wanted with the free level dissolve our is the redundant debates that you make with the results in performance bottleneck on what I mean by redundant to be hates is the multiple wrong clips that you make for the same data. So let me this explain you example. So let's suppose that there were 10 task in sort of the table on all of this task articulated about the user John. So now if the graphic lined us for the list off task, we basically first of all find the task list using the task query result were and now for each task were basically hitting the user collection bright. So it's 30 beak ready on. This is going to run for eating every task object instead of their task list. So since we have 10 Tusk, this thing is going to run 10 times. And since the users seem you're basically performing 10 reputed queries to get the John detail, right, so this is the multiple round trip problem with the database that you face using the free leveled result were. So if you are now wondering, Is there any solution for this? Yes, there is on its called US data loaders. So tell orders is a general celebrity created by Facebook on it is used to bat and cash your data access layer request. So whether you are fetching from the database or maybe from some Web service, it's a general liberally that health soon betting and cashing. Now this library is not simply dedicate Lee built for graphical, but it can be used in graphical and we're going to do so. But as I said, it can be used outside of the graphical as well. This is not something specific to craft will. So now they're to be administered water and buy off the detail orders. Let's also see a small demonstration off this my people database around trips that we usually face. So I basically go to the court base, and now we'll go to the database utility file. And here I am going to simply set the conflict called as mangoes Dot said, And I'll set Option Caldas de Book on for the Value will simply say to. So what this will do is it will print out all the devi queries to the console that this performed by the mangoes. So it will be very easy for us to practice all the data base hits that are performed by the mangoes and let me show you the reputed queries salute scored with the browser on Let's try to hit Digital task on. I would like to also fair to the user information over here, so going to space for user and let's suppose there for the user we want the i D on the mail on. Currently, the limit is five on. If I hit this particular credit, we get the five record video user information Also. Now let's go to their time. They'll presidency of a new surge. Did the book as true on the money goes, this is the kind off logs that you get on. These are nothing but the DB queries. So, as you can see, there is this one query hit to get the list off task. And now for each task in sort of this task list, we have a free level. There's all over which is running on. Let me even show you why going toe the task result would, As you can see, we have this free level. There's already find over here. So it is basically hitting the user collection and finding the user detail by the user i D , which is present on the task object. So since the limit is five, we get the cast list as five, and for each object or eight task, we're fetching this same user again and again five times from the database, so As you can see, this is the kind of issue that you face with the field level dissolve were on. Just imagine if we increase it in a more off the cords that we fit. For example, if I increase from five, repent on these problems becomes worse and worse. Let's call their terminal. As you can see now we have 10 database hits for the single user. So this is where the library like data loaders comes into place, and it will help us in, basically, badging all of this request into just single request. So we will reduce demand. People grounded its databases to just single round trips over here. On off course, we will need this one pretty forgetting the list of tasks. So with the help of data loaders, we will reduce this 10 plus 1 11 queries tojust took. Where is one to get the list of tasks and one credit will get the user detail. That's it. So your 11 database hits will be reduced to just food database hits the tolerance also provide the cashing as well, and what cashing will do is it will basically cashed the result on If you try to access the same idea in the next 20. It is just going to give you the result from the cash. It is not going toe again. Hit the user collection. So in that case, there will be just one database head which will be just this one to get the list of tasks so this can be achieved with the cashing. But I don't really recommend cashing because they're supposed their users updated his information. And if you keep trying to return the same cashed result, then they down the you. I will be ambiguous. So I don't really recommend you to use the cashing. So I think the best thing is more than enough on will solve the purpose. So you guys, I hope you are able to understand the world and buy off data loaders with life demonstration off this issue. And we're going to fix this issue in the next video using the tellers implementation. So I hope you were able to follow along for this video on. I'll see you in my next video 37. Implementing Data Loaders : Hello. Everyone on in this route of yours going to implement the data loaders. But first of all, let's understand how the middle of this work by an example, So going to create a file over here called us data Liudas iphone example dot years on. I've prepared some court already just to explain you so into pastry to work here. And of course, we need to install the dollar. That packet so here gonna say and am started a tall order. So as you can see, it is done installing. So now let's see how the data largest basically work. So first of all, you have to create a new instance off the data order on as argument it takes batch loading function, which basically takes list off keys or ari off keys on. It returns the values which results as a promise. So remember that for your bats loading function your function Children don't know ari off values, which results as a promise. And if you're wondering that here we are not returning the promise. So as we discussed in the think of it video that whenever you're placing keyword to a function even though you return a normal value. It is going to be resort as a promise on just to explain you that resolving a promise is necessary for the batch loading function I'm going to remove this season. Keyword. From here on, we like to run this fight. So gonna say Nord Ludo's example Door Js Then, as you can see here, we have a bunch of feathers on here. It says that the loaders must be constructed with the function which, except sorry off keys on returns, array of values, a promise. So since you're not returning the promise, we're getting together. So I'll make this function easing. So our value is result as a promise. So that's one thing on as what is loading the keys instead of the r. A. Is concerned you can basically lord it using the Lord mattered. So whatever you specify over here will be pushed to the list off keys. Right now, the most important caution here is that Van does the batch loading function actually execute So your badge during function execute within a single take off an event. Look, And if you're wondering, what is stick think is nothing but an attrition often event. Look is called a stick in Norges on. If you don't know about the event, look, then I would suggest you to research around it, because that's how the JavaScript works behind the scenes. And it is one of the core competent off how things basically moves. But in short, I would like to tell you that the Rent loop is responsible for taking the items from the callback you or the Event Cube on put it inside off the call stack than the call stack is empty. So that's what the responsibility off the loop is and each attrition off the event loop. Which pigs there come from the Q and put it inside of that stack is attrition and it's called a speak. So I hope you understand. So this means that whatever keys that you have lorded within a single takeoff event loop will be exhibited all red ones on all other lord function that you have performed in some other takes off the event look will be executed separately. So this means that this one poetry is going to execute wallet ones. Then this set time Oh, basically don't a synchronously, so this court basically goes into the callback. So this basically means that this particular court is going to run in some other event. Look, take as compared to this one. And same goes for this one as well. Hands, we will have basically three bad user function called over here. One for this one for this. And one for this. Because all of these three will belong to three different takes on. Let me try to show you say, find on this file, for example, Lord digital orders example dot years. Then, as you can see here, I've properly added the console logs, which is bad user called. So as you can see, this is called three times because all of this three piece off cored runs in different take off the event loop. Hence this batch of their function or we can say batch loading function executed three times. No. One more thing I would like to show you is that if you provide the reputation keys over here than it is going to be ignored by the data loaders, So let me just run this again Then, as you can see in the fourth batches of function called, we just have single value over here. We do not have repeated items in the area, which is 111 We just have single one. So you don't have to worry about pushing the reported keys inside off the Lord function. The Dallas is going to take care of it. And yet, is this worldly some basics off the Callejas that I wanted to discuss with you? Now let's push it further to implement the data loaders insert off a replication so going to exit from here on, the first thing that I do is tow, create, afforded over here called us loaders on. Instead of this, going to create a file called as User Daughters on here went to export a function guarded as bad users. And this is going to be a batch loading function which will use insert off the data. Instance on here. We'll have access to the list off user ID's an oil import, the user model so their big infested it off on the database. So gonna said const. User equals to require I can get it from databases models slash user No, here. All right, D query are to get the data so far, Solo de Concert logs so that you can say properly. So for the console over, I'm just going to print or the keys on here going to simply say, User ID's on here. Gonna say const. Users equals toe a bit. User dart Fine on. I want to find on the underscore i d Field and now we want to fetch all those user whose I D is president. Insert off this list. So when two meters off the in operator on going to pass the list over here, which is use the writings. So I hope this makes sense. And since we are using the R word, keep it over here. We need to make this function issing, and also because it's a bad loading function. We have toe resolve this as a promise. So handsome in it to make this function is ink on board. If we need to do is this quality is not going to return the in the exact same sequence as we have specified over here. So let's suppose that the use already is in the sequence off one two on three, then it is not necessary that this is square is always going to return the user one on user too. And user three in this sequence, This great. He can't return in any sequence because that's how the doubles works. So to fix this on Britain Desert in the proper sequence, we're going to retreat over the list of his radio here on. We're going to find out instead of the users on going toe, returned the appropriate object. So let ministry movies on here. Gonna simply said it done. First of all, I'm going to it right over the user ideas. So gonna so use a rightist dark map? And here l A get individually is ready. And now I can find this was already inside of the users list, so I can say users don't find on Dhere. I'll get individual users. So here I can simply say user dark Heidi, if this is equal to the user ready that we got from the list off use already than simply return this particular object. And since we're using the map over here, it is going to return the ari off user object which are going to be in the same sequence as we have the list of use varieties. So I hope this makes sense. And now, while creating next gorgeous filing the Borders folder so that we can export every law order that we created in just one single fight. So gonna simply say, const user requests to require And I can get it from the user order on here. Anything with a model dot exports, because for an object and going to export the user Lodeiro here and now, since we have exported, what we'll do is we'll use this particular batch user function inside of the context object because I warned the loaders to be available inside of the context object so that it can be exist in multiple result, but or we can say in every dissolvable. So let's go to this hardware. George's first of all going toe require the data loader package on then also going toe require the batch loading function from the Lord's Folders of genocide. Const. Lord is equal to require and I can get it from the loaders folder. And now finally here in the context, I would like to add the lorded over here on it is going to be an object which will hold my people orders. So the 1st 1 that we have created is the usual order. So will name the key here as user and will pass the new instance off the data loader. So the best loading function have access to the list of keys, and I'm going to simply pass it toe the law orders, dart user dart badges or function on going to pass all of these keys over here. So I hope this makes sense. And I think we can remove this console log, which is contextual, and it is no longer required. We're not using it now. It's time to use this. They tell odor inside off the task of free level dissolved. So let's go to the task for level resolver on. I'm going toe basically come in this out on from the context object electrifies the loaders so we'll ignore the argument. Object on from the context object. I'll have access to the borders. So here I can simply say, const. User equals toe await Lord us Dart user Dark Lord and hear. Any positive is ready so I can get it from parent dirty user and I will have spoken word this toe string so that it is easier for the data loaders to basically omit the repeated values, since it will be primitive, otherwise barren. Don't use herbal basically past the object. Tidy toe the list off keys on data loaders won't be able to compare the re protect kids because since all of this case are object, just because the object have same meglio doesn't mean they're equal and it won't be ableto eliminate the duplicate keys. So hands are suggested to pass the primitives over here by converting this toto string. So I think we're good to go. We have added the orders instead of the context, and we're using it over here on the field level is over. Now let's see, what difference does it bring in terms off the database query that we fire? So they escorted the browser on the fresh and if I heard this particularly appear now then as you can see, the first thing you would have observed here right over is that the Reserve guard return quite faster, as compared to the previous curry and now alert school with their terminal in see how many credit card fired. Then as agency, there are only two credits fired. The Force one is to get the list off us. We just president over here in the Tasked level result were, as you can see, but for the each free level, dissolve work ready. We just have single rate. I was hit earlier. We were having the tender doubles hurts without bail orders. But now it is just radios to wonder. Tapas hit on the fare level. Results on the total is just to queries. So as you can see, how much performance improvement does the data loaders brings to your A. P I And in fact, let me just probable comment this out over here on just observe their difference. If I just income in the previous query, let me go to the browser and just observe that there will be minor delay in the response that we get from this hour because so what has to perform a lot off queries. So if I heard this then, as you can see, there is a lot of delay. Then you will get the dessert, as you can see. No, you got the result. And if I go to their criminal then as a country because 10 credit's got fired, and now if I basically coming toward this thing again on uncommon the loaders on. Let me see these. Let's go to the browser and hit this again. Then, as you can see, how far do we get response? Because our free level diesel or query only hurts one time. So this is how you implement they get orders on. There is one more thing that we discussed that detailers not only bad she request, but it also cash your request. But I wouldn't suggest you to go with the cashing because if you're returning, the cast fizzled. And somewhere in between, if some of the user information got updated than you will give them biggest information back to decline, so you shouldn't do it. But I'll show you how can you cash your data lulus request? So with the cashing what'll happen is that as long as your list off keys are not changing the data, Ludo's is going toe, give the cash reserves and it is not even going toe fire this single quality because it already has the result the first time that you fired. So let's see, how can you basically cash it? So if you go to this our Georgie s. So currently works happenings that you are instance creating digital orders instead of the context. Right? And we know that context runs on each request or request. So on each request, you are Reinstein shooting the data loaders hands the cashing is not able to perform. To make your cashing will properly, you need to move this article the context So going to simply remove from here on gonna simply say, const user Lord er on. This is going to be quinto this and I'm going to pass this user order over here. Nine if I save this. Andi just observed the logs in some of their terminal once I hit the FBI. So if I heard this, let's school to their criminal than for the first time. We have exact same scenario. We are finding the list off task. Then there is this one data base hit to get the user right. So again we have a book Where is fired in total? No, If I hit this again, let's see what happens if I heard this a pair again. Let's school with their terminal Now, as you can see Onley, the task is fired. There is no user dot find again. This is because your list off keys is exactly the same on Hence your batch loading function with this bat user Dane trend. Because again, as I said, the list off keys is exactly the same, and you are basically cashing it. But again, I wouldn't suggest you to go with the cashing because let's suppose that behind us in user teens, it's detail, for example, the name. So let me just ask for the name as well. Now let's suppose that the John updates its name from John do John something else. Then if you just keep on hitting this, it is not going to credit the user collection. It is just going to credit the task over here, right? So you would end up sending them biggest information back to decline. And if you're wondering that, were that the square is where we're finding user? Don't find one. Email. Jonathan Demeter comes with this query is getting fired from some other place, which is this one? Let me show you. It is getting fired from the context. So if we go to the helper context index gorgeous, as you can see, we are basically are finding the user on the basis off email provided in the token payload . So don't get confused with fine one Kredi with the users. Start find that we are here head on. This was basically fired by the bad loading function, but this is basically find one is fired by the verify user context helper. So these are completely different. So I hope now your nest. And how can you basically cash your data loaders? But I would suggest you do not cash it. So what I'm gonna do is I'm going to move this again inside off the context function. So going to remove this from here on going to simply pastry the whole year. And if I say this, go to the closer on, hit this again then if I go to the terminal, the residency again, this users don't find this performed are to get the user details. So you guys, that's it for the data loaders betting and cashing. Andi, I hope you were able to follow along and thank you so much for watching this video 38. User Subscription: Hello, everyone on in this video, we're going to implement the draft. You'll subscription into our policy. So far, we have worked with equities and mutation. But now it's time to work with subscription. Now, as you know, that subscriptions airdrops are real time communication between the client and the server using the Web. Swaggarts. So we need to do some configuration on this or what itself to make the subscription work properly. So the first thing that Aldo is to basically make yourself a method available on the political instance on that McCurry's installed subscription handler Salvage do it. So here gonna simply say, Apollo, sir, Will dart installed subscription handler on this basically requires an instance off actually possible so we can get the instance often extra divisible from this abhorred listen method. It basically returns you an instance of are actually possible. So here you wanna simply said, const extra piece of work on I basically get this on going toe. Pass it instead of the install subscription handler, and that's all in a dodo as what is The conversation is concerned to make the subscription work properly or not express up. Now let's put it further on do some changes instead of the context function so they can taste function. Received the request response optic in case off Kuwaitis in magician. But in case off subscription, it doesn't receive the request object. Instead, it receives a connection object. So here I'm going to simply could have their particular object. Onda. Since we are doing a lot off task over here, the request we need to go it on living. The request object is available. So now I'm going to simply check if the request object this president or the connection objectives President and accordingly will prepare the context over here so fast, relied. Say const. Context will be j equals an empty object on here and see if the request object is present. Then simply call this particular method, which is very far user and going to move both off this thing over here. So I'll say context object Dort emails because toe request for the meal on seem over here as well. So I hope this looks good and we can set the loaders in both big asses. That is whether it's a query, mutation or the subscription so going to move this out window remove district in statement . Over here on here Gonna say context. Always a dark loaders on it is going to be equipped with this particular object. And finally, I'm going to return the context object over here. So that's all we need to do. That's what is the confiscation is concerned. Now let's push it further in the type definition. So here, in their type definition, I'm going to first of all, define the type subscription, which is again a root level type on just to extend the subscription in my people, other files going to define our dummy freely over here. Are you concerned that my subscription over here? No, as I said that we're going to define a subscription for the user, so that's a region is going to run as soon as the user is created. So let's go to the user type definition on here, going to someplace extend by subscription on the name of this obsession I call it Does User Created on this is going to return the user object? No. Well, basically, create our subscription for lead over here. They're gonna say subscription on inside of this going to create index George's file and you're going to first off. All require the pops up from Apollo, said Will Express library on Dhere, going to simply say model, not export equal to new instance Off the pops up now, using this pops of lottery pick unpublished on substrate appearance. But first of all, let's also defend the events is well, so here, going to create our new folder called As Events on Insert Off This. I'm going to create the event file for the user. So this will basically hold all the events related to the user's gonna say model North exports equals an object on I want to export anyone called as user created Anencephaly is goingto be user created now, like ways you can define areas of the revenge is well in this event folder. By creating dedicated file on, you can export all of them in settle for one filed Caldas indexed gorgeous. So here gonna say const user events equals to require from the user file on Dhere. I can say model dot exports was an object and going toe export the user reverence. So I hope this makes sense. We have defined the user lettered event in the particular user file and likewise, you can define different events in videos, other files Onda. Finally, you can export all of them at one place. So now that we have the pops already as well as demonstrating now let's go. But there is a word so I'll go to the user is all over. And just like we have this query object over here and imitation object or here in which we have defined the mutation result wars, let's also have a subscription object over here. So in a sense subscription and again this is going to be an object. And here you can define the result war for your subscription. Know the name of the subscription is user created. Andi, Unlike the query in the mutation where you have this all what is a function But here in gets off subscription Your is all What is an object on? It has this upset matter. It's basically returns. The single traitor using the props of literary on also specify the event so that the Afghan loans that this particular event isn't subscription. So first of all, let me require deep up, sublime ready So we're gonna say const But so on this basically comes from the subscription . Fuller and I would like to also required the user. Evans on this will basically comes from the Event folder, which is president instead of the subscription folder on Dhere. Eye Candy Structure. The user Revenge No, let's go here on day here. I'm going to simply say pops up Dar pacing it Ritter on going to pass the name of demon. So the name of the event is usually rent dot user created. You can name it whatever you want, but just make sure that you keep it consistent where you define your subscription on very you publisher event. So no eyes off. Now here we have basically subscribe, but now it's time to publish. So of course, we're going to publish this user created subscription when the user is actually created on these there is basically created in sort of the center of mutation. So let's publish an event from here. So just before returning the result, I'm going to simply say pops up dark publish. And here in the fourth argument, you have the positive name off the vent. So which is user event DOT user created on in the second argument, you have to specify the payload. Now. The key off the payload is same as your subscription in which is user created. And then you have to actually pass the payload or the data on. There's nothing but the desert over here that we get from the Mongols query. So I think your subscription is ready. Let me see if this let's go to the browser and they're fresh on. If you go to the documentation that has agency now, apart from Kredi and Mutation, you can also see the subscription over here. So now let's try to execute this. And now I'm going to run this subscription in a separate window so that you can clearly see how it works. So going Toe Bundy separate window, Ondo. Minimize it so that you can see this clearly on going to open. The Afghans are over here on here, really basically done. This subscription on the name of the subscription is user created, and I can ask what the field suggest. I d. Name email off the user ID. So let me hit this now that as you consider this thing listening now let's go to the user. A P I on Let me open again This as well so that you can see properly. So I simply I just did this to Windows already even see clearly. Now, now let's write code on the invitation called Let's sign up. So here gonna say gradation, sign up on here. Going to simply say Sign up Over here on here Been in the past. Leaders are human instead of the import object, so we'll pass things such as name, which is required and alerts colored. For example. Bob for the male, I'd say Bob 12 at the rate gmail dot com on hearing the last argument unit opacity Password , Solar cell pass. 123456 And as a result, he wreck announced for the idea itself. Whatever it is, I can ask for the name. And if I hit this sign up, let's see what happens. So as you can see as soon as this item addition is done, the said, well, basically returns this value, which is user created, and it has all the feels that we asked for. And if I create multiple user over here, we're going to get multiple data over here because it is continuously listening. So, for example, if I create, for example, Bob 13 and I named this as Bob Curtain on. If I sign up, then as you can see, I got bebop turning over here. So you guys there solve the subscription work and you can stop this to stop listening to this particular subscription. So, you guys, that's it for this subscription on I hope you were able to follow along on. Thank you so much for watching this video. 39. Format GraphQL Error Response and Query Variables Overview: Hello, everyone on in this room. We are going to have a look at the for mating. The other message on making use off the query variables. So far, we have only used the issue to behead us over here. But no, we'll also see how to use the query variables. So let's first of all work on the formatting error response. So, for example, let's supposed 35 past any of the wrong fields over here because I want to generate and Heather message. So if I hit this, then as you can see, this is the kind of header My situate gate. We get the complete stack trace over here, but if you want to minimize this error message that you get from the server, you can do so using the form ahead of function in sort of the Apollo server conflict Veterans every time the terrorists undeterred inside the A policy that would Now let's go to the court base on here in the Apollo server conflict, you can make yourself our function called us for a minute on this former better basically has access to the other object on. You can make it off this error object don't need the things that you want. So I'm going toe itself not simply control of the air objects so that you can see properly . And I'm going to simply return the other from here. So let me see if this large school to the browser on fresh and I'm going to basically hit this again on Let's go to the document allow. So as you can see, this is the kind off air masses they do get from this error object that is coming from here so you can take all the things that we want. But for me, all I warned is the message itself, because that's more than enough. So here, going toe, instead of returning the whole adult object, I'm going to somebody it on the message like this. So Venessa message as at a dark message. That's it. I'm going to save this. Let's go to the grocer. And if I hit this now, then as you can see, this is what I get. I simply get the Adam message right, and, for example, if I passed, this is correct value Right on. Let's suppose that we try to hit with a user which does anyone exist in the system? If I hit this as you can see, I get minimalistic added message so you can make use off this other object. And you can pick up the things that you want from this whole other object. No. One more thing I would like to show. Use that. First of all, that money will disconcert log. So so far, we have only used the extractive beheaders. But if you're wandering water, this query variables so you can make use off this query variables to pass dynamic values to your operations such as mutation. QUERIAN subscription says off. Now, if you see here were hard coating this value So now we're supposed that if you're using this values in multiple operations, right in multiple inquiries or multiple invitation, you have to repeat this same values instead. What you can do is you can declare them in this query available so that you're going to use it. So, for example, here in the log in, I would like to pass dynamic values from the query variables. So what's the one word I have to do? Is I have to be finally variable like this with a dollar sign on the name of the variable on you can name it whatever you want. I want to name it email and you also have to specify their type on the expected day for the email is string. Then I specify the password is well on again. It will be off type string and known the level. And now I'm going to use this video will over here. So I'm gonna say email over here on here, Going to simply make use off the password. Now all we need to do is to pass this dynamic variables from here. So here will they find the email as, for example, john at ST Ziemann dot com on going to define the password. Also as what is number 123456 on We're good to go. Let's hit this now. As you can see, we got it open back. If I pass anything wrong over here and if I heard this then as you can see, it says user, not phone. So this is how you can make yourself this query variable. And now you can reuse this variable in my people operations such as you can user in sign up as well. Or maybe in some other places. So I guess there treat for the formatting, the other response as well as using the equity variables. I hope you were able to follow along. And thank you so much for watching this video. 40. SOURCE CODE: