Okay. Okay. So that was five minutes, I think. Did anyone get through this? Was anyone able to update the GraphQL type definitions to include author and subject and then craft the mutations to add those to the Graph? Anyone able to get that done? Okay, well let's take a look at the solution. So we have got about 40 minutes left and we have a section on custom logic in the authorization section, which I want to make sure we cover. So maybe let's take a look at the solutions for this fairly quickly and then move on here. So my container has been hibernated, I'll refresh that. So this happens sometimes with Code Sandbox that it will go into hibernation, we need to give it a restart. I think overall Code Sandbox has been pretty good for these sorts of workshops. I think it's... there's a trade off right between these using online tools like this or getting your local development environment set up, which can sometimes be a challenge in these sort of online workshops but I like Code Sandbox, so okay we said we need two types, so we're gonna add an author. Author has I think just like a name and subject, which also probably just has a name, we'll make these fields required or non-nullable, that's what this exclamation point means, that to create an author node, it needs to have a name, to create a subject node, it needs to have a name and then we need a relationship field, so an author, an author can have written one or more books, so we'll make that a object array field and then we wanna use our relationship directive, so the author, let's say author wrote a book, and then the direction, so we're going from the author to the book, author, wrote, book, so in this case, from the author, the direction is going to be out, and then similar for subject, subject will also have, call that field books, And the relationship type, which we call this one, a book is about a subject, and so in this case, we're gonna go from the book node, the book will be about a subject, so for the subject type, the direction will be in. And then we also, on the book type, we wanna be able to go from the book to the author and the book to the subject, so we'll say authors, I think, so a book can have multiple authors, so this I think should also be an array field and we'll need a relationship type, which we said was wrote, so from the point of view of the book, the direction is gonna be in because we're gonna go from the author in to the book. And then similar for subject, so a book can have zero or more subjects really and a relationship directive, so the relationship we said for this one was about, oops, missing our double quote there, so direction this case is going to be going out, so we're saying the book is about subjects, Andres says he's dropping. Yeah, thanks for joining, yeah, there is a recording I think that will be sent out and yeah, thanks for joining, okay, so we'll save this, I didn't command us, we can also go to up here file save, you can see this triggers a restart of our GraphQL API application, and I think we need to refresh this browser to get GraphQL playground to reload the type deaths, but now if we look in the docs, we should have authors, yeah, we have authors and subjects cool.
Okay, so we have this table, we need to write GraphQL mutations to add the authors to our books. So let's do that, so we have a book called Inspired that was written by Marty Kagan. So let's take a look at how to do that. So we're gonna delete that, this is gonna be, I know it's gonna be a mutation. And we need to decide what way we want to start. There are a couple of ways we could approach this. We could do update books and search for the book and then connect, or do a create operation rather from the book to create a new author, or we could do create authors. Maybe let's start with that. So we'll say Create Authors, author has a name, but Marty Kagan and then Marty Kagan wrote a book. We already have the database. So this is gonna be a connect not a create. So we're gonna connect where the node. So you may notice that we have to say, connect where the node if we had properties on the relationship. So we haven't talked about this yet, but so far we've been storing properties on the nodes. If we had properties on relationships, we would have another option here to filter based on the edge object, which is basically, which is anyway, that's why we have the node here, it seems like an extra layer, but it's simply because we don't have the edge filter cause we don't have any relationship properties. Anyway, we want to filter where the title is inspired and let's get some more real estate so we can see what this says. Then we'll bring back authors, name, and books in the title of the book. And then we also want the info to tell us if we create any nodes. Okay, let's identify this and look at this. So what are we doing? So we're saying create authors and here's the input object, create an author, set the name to Marty Kagan, then for the books relationship field, we're going to connect to existing books where the title of the book is inspired. So let's run that. And we say we've created Marty Kagan, and Community Inspired we created one node can verify this if we go to Neo4j let's look for author. Here's Marty Kagan, you can double-click to traverse out, you wrote this book inspired, which is all about product management. Cool, okay, great. So that was updating to our schema, adding authors and subjects. I'm gonna skip going through the rest of the authors and the subjects so we can move on and have time to cover the remaining section, but you can imagine how we use those nested mutation operations to create the authors and subjects. You can find the solutions linked in the sandbox too in the readme if you want to check that out. Cool, so let's move on. So we've talked about writing our type definitions that then drive the database, drive the graphQL schema that's generated that gives us the CRUD operations for creating data. What about custom logic? How does that fit in? That's what we're gonna talk about in this section. So I'm gonna do some setup here, you can follow along if you like, but you don't need to. Let's clear out our database. So because we were going through that exercise and we have somewhat different schemas, I'm gonna do another, match a, detach, delete a. So let's delete everything in the database and then we have a new code sandbox. Let's copy the link for this one, drop the link in the chat. Let's do that again. So this is a new code sandbox, which means we'll need to update our.env file again. So I'm just gonna copy that from this code sandbox. I'm gonna click that link that I pasted in the chat and then we wanna fork this code sandbox. So we get one that is private to us and I'm gonna paste my credentials into that.env file and save that. So our API application will restart. So this schema now includes a bunch of other things. It includes the author. Yeah, so author subject. We also have these cypher directive fields now where we've added some custom logic. We even have a new weather type and if we look in Index.JS we see we've actually like implemented a resolver here. So this code sandbox, we're going to talk about in the context of adding custom logic. So you want to follow along with that code sandbox, you can see some updated code, but to finish the set up we need to run this mutation to create some data based on the correct full schema. So that included authors and subjects. So that is running to save some data in our Aura instance. You can see we're creating the authors for each book, the authors for each book, handful of books, and then creating customers and some orders. I guess there's a couple of notations operations here. Okay, cool. So let's talk about custom logic. So we get a lot that is sort of generated for us for free essentially by the Neo4j GraphQL library based on our type definitions.
Comments