So here, let me pull up warp. So we've run our migration. We have studio running. Let's check out our playground. So way back when, the very beginning of this workshop, when I ran YarnRedwoodDev, after I installed everything up here, we ran YarnRedwoodDev, it opened the front end that we looked at on port 8910. And it also opened up if you come on down port 8911. So I'm going to click on this, and this opens up the, this is actually the API side of our application. So if you go to, if you have Redwood running, and you go to 8911 and pull up slash GraphQL, this will pull up the GraphQL playground. So now that we have our database running, we have one line of data entered in as a user. Now we can play with that data inside of our GraphQL playground. So the cool thing, this is automatically included. You can click on this for docs and see that we have queries. And if you come down here, you can see a few things that we've already generated. Now, you can see the current user and Prisma. These are just basic things, but we've got to generate the GraphQL side in order for everything to show up. So I'm going to come back over to Warp, and we're going to use those Redwood generators that we were using before. So here, I'm going to say Yarn Redwood generates. You can do Scaffold. Scaffold is kind of interesting because it will create your GraphQL files. It'll create pages for you. It'll create forms and you can see all of your data directly on the site. So if you just want to style stuff like have Redwood generate it and then you just go in and change the styles, Scaffold is great. Scaffold, in my opinion, can also be a little overwhelming sometimes because it does create a ton of files for you. Actually, let's go ahead and just create one. I'll do Scaffold Link. I'll show you what I'm talking about. So it'll do all those things. I think that it'll kind of show like a warning at the end. Yeah, there is a build error because part of the problem is it can't, we haven't generated everything that it needs. But you can see it generated a cell, which we'll talk about cells. We're talking about pulling in the information. It generated a new link page. It generated our tests, created an edit page, a link page, all the things. So I'm curious, let me see what this, did let me do local host 8910 because this was our front end yep yeah it ran into a couple errors there so i usually like i said i usually don't run all of that because it it does generate a bunch of stuff for you so if you come into components uh that was the one we already created let's see pages it looks like it was just a build error so it didn't do it okay cool that's good because I wanted to take this one step at a time okay so I'm going to say yarn redwood generate we're going to say SDL because that's what we're generating on the background generating an SDL file and we need one for each of our models so as far as I know you have to type this line for each model that you have so it says that there's an error and basically that's because we've created relationships see looks like you have a link model in your prisma schema for a relationship, but we don't have an SDL file for your link yet. So we've got to do that for links. If you see an error there, don't worry about it until you've written everything. So you can kind of, it'll should kind of tell you what you have to write. We can, yep, looks like you have a comment model in your Prisma schema. So we don't have a SDL for our comment yet. So let's write that for our comment model then let's see what else does it need once a favorite model whoops so now it'll do it for favorite and then it's saying we have votes we haven't done it for vote yet perfect so now i've actually gone through all of my models so you'll see that there's no errors. So if you, like I said, if you start seeing all those things when you're generating SDL files, don't worry about it. Just kind of follow the arrows, errors, and it'll kind of guide you through all the things that you need. And you'll see that my issues over here on the left with my server cleared up as well. So now that we have those created, I'll show you what files are created. We're still in the API directory. This is inside of our source. We have a GraphQL folder. And this created all these SDL files. And if you look at this, this is very similar to the Prisma, the schema that we looked at. But the one main difference, I will point this out, is that our schema.prisma file, anytime we had an optional parameter, we used a question mark. The GraphQL uses the opposite. And so anytime it's a required field, it uses an explanation point. So sometimes that can get a little confusing going between the two because they're referencing the opposite. We created a SDL file inside of our GraphQL folder for all of our models. And then under services, we now have a folder for each, basically for each SDL file. So if you open this up, this has scenarios where if you wanted to mock data out and use that for testing, created a test file for us and then you also have your services and this is uh if you're not familiar with with uh GraphQL what it does is you establish your types so I'm saying these are my types for my users these are the queries that I want to run so I want to be able to grab all of my users and I want to be able to grab an individual user and then these are my mutations that's for all user definitions. So if you're thinking, oh, you skipped over these, this is just a way of saying when I create a user, these are the fields that I wanna collect. And that Create User Inputs gets passed in here so that you're not having to retype all these out each time, you can actually just kinda use a shorthand. So that's where that's getting referenced. So I'll say it again and just walk through it a little bit slower. But with GraphQL, you're defining the types that you need. fields that a user will have. And we have, these are the fields when you're creating. These are the fields you have when you're updating. And then you have a list of mutations or sorry, mutations are down here. So mutations is anytime you want to mutate or change the data. So if you're creating or updating or deleting, you're changing that data. If you're just querying for it, like kind of selecting it, then you're using a query. Okay. So Priscilla asks, so the yarn generate for all these models would automatically justify the type for all your data that's right so all of my data is tight safe everything and i didn't really have to do anything i just defined say didn't do anything i defined it here in my schema dot prisma file and then uh if you normally work with other projects with graphql you have to write all this stuff out yourself you also have to write out all of your uh resolvers which we'll talk about in a second you have to write all that out yourself, and it just becomes very, I don't know, copy-paste, copy-paste. You feel like you're very redundant. You feel like you're writing the same thing, so Redwood generates all that for you, which is really nice with that generate command, and then it just makes sure that all those types match up with that schema file, so if you do something different, it will realize, it'll tell you, hey, you're not doing something right, so we have our users file here. We talked to, sorry, we have our users.STL file. We have our types, we have our queries, we have our mutations, and then resolvers is how it figures out what to do with that. It's like, okay, yeah, you said you were going to query all this data. How do you actually query that? Like, what are you actually doing? Like that, where's that coming from? Or you're saying create a user. Well, how does it know create a user? Where did, what handles that code? Well, that's here under services. So we have here for users.ts because it's a TypeScript file is our users file. And this is where we are resolving, we're telling GraphQL how to handle all those things. So if you pull up the users SDL file, I'm gonna pull this up in one pane and I'm gonna pull up my users.ts file in another pane. We'll get these side by side. So anywhere where I have a query, it should have a corresponding piece here in our users.ts file. Just trying to move this over a little bit. There we go. So you can see here, users has a corresponding users here. User singular, where I'm passing in an ID, has a corresponding user right here. So if you make any changes in your SDL file, you'll also want to change it in your resolver file because those two are linked just by the name that you're using. So like create user. Well, here, here's create user. Here's the code that's actually creating the user.
Comments