From the course: GraphQL for Enterprise Developers
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Solution: Creating a Cat entity - GraphQL Tutorial
From the course: GraphQL for Enterprise Developers
Solution: Creating a Cat entity
- [Instructor] All right, let's give this a try. We're going to go to our schema, add the key directive, add the lookup fields, which we will add here. So, we always want to make the Cat the entity. We're going to extend the entity over here in the dog schema. So here we'll say type cat at key fields:id and then this is where we'll say ID and let's call it dogBestFriend. Keep it consistent and then we'll say Dog. Alright, so that should be all we need to get the schema dialed in. The next part is the resolvers part. So that will mean that we open the index file. Okay, so we also need to add a cat object here and we'll say dogBestFriend. This is a function that will take in the ID of that dog and then we'll look at the dogs. So we'll say dogs.find. For each dog we want to check to make sure dog.unlikelyFriend. We'll make sure that it matches that id. So let's get this whole thing running. We're going to npm start. Then we'll start the dogs cd dogs, npm start. Then we're going to say…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.