This course has been updated! We now recommend you take the Server-Side GraphQL in Node.js course.
Transcript from the "Course Code Overview" Lesson
[00:00:00]
>> Scott Moss: Open up the repo, we're gonna check out to lesson one. And first things first, I'm also gonna give a walk-through with what's in this repo. So there's a lot of stuff in here that you don't have to concern yourself with,that's already done for you, that's out the way.
[00:00:12] So we can just focus on just the GraphQL parts. But I want to give you an overview of what's there so you have some context, so you're not just like, what is all this stuff? Okay, so the first thing is let's check out the package style JSON, and we will look at some of these scripts.
[00:00:26] So we have a test script, this test script is gonna run all the tests inside of this repo. You almost will never have to run this one, because we'll be running tests on a per branch basis. So like I said, these different test scripts down here, like test schema, test resolver, test interfaces.
[00:00:45] These are gonna be where you're gonna be running tests for the current lesson that you'll be on. So these are the descriptions that we'll be using the most, and in the README it'll tell you which test script to run. And when you need to run it, on what branch, we have this dev command.
[00:01:00] This is what you'll be using to actually start the server. This command uses something called nodemon, which basically is like Node, except for it watches the files that I tell it to watch. And when you save that file, any changes that were made, it'll just restart the server for you.
[00:01:14] So that's why we have a dev command here, so it'll rebuild it every time we save a file. So we don't have to stop it and restart it, which is annoying during development. And then you have the restart command which is part of this dev command. And then the start command, this is what you would use in production.
[00:01:29] You don't want to use that restarting, developer, server in production, you just want to start it normally. So that's the start command, so if you deploy, this is what you would use. I got some other ESLint stuff in here, Babel, we're using Babel to transpile everything. It's using Babel 7, so we got support for like imports and exports, ES6, stuff like that.
[00:01:49] That's how we get that, because we're using Babel. ESLint setup and Prettier, so you can have the linting in the code formatting, so you don't have ugly code, I hate ugly code. And then JSON Jess configuration to get Jess working. Did a whole much of other GraphQL dependencies that we'll be using.
[00:02:08] So the next thing is, let's see, like I said we got the ESLint set up here, you can check out the rules. Feel free to change them if you don't like them, these are just some of some of the rules that I use and some recommended ones. The Babel configuration is pretty minimal, uses the current version of Node.
[00:02:24] And we just added some class properties which we won't even be using. And then object I like to to object spread, it's pretty legit. And from there the only thing I want to take a look at is the actual src folder, so this is where all the work is gonna be happening.
[00:02:39] So if you hop into the src folder, a couple of things we got here, we got this config folder. And basically what this config folder does is, I've built a lot of APIs, and what I've found out is that. When you put all the configuration, I'm talking about secrets, database strings.
[00:02:56] Variables that you use to toggle things on and off like logging, anything like that, environment variables. If you put them all in one place, it's a lot easier to progress through your application. That way, you only have to change the configuration in one place. If you put them all over your app, you gotta go in many places and change them.
[00:03:12] So I like to have this config folder basically, which has like a base config. And then depending on what environment variable you're in, it'll load up the appropriate configuration file. And then merge them together. So we have a base config here, if the Node environment was developmental, it'll load up this dev.js and merge the configs here.
[00:03:30] And then now you'll have a development file, or if it was testing, it'll load up this testing one. If it was production, it'll load up a production one, this allows you to switch configurations based on the Node environment. So that's given to you for free, the other thing is, we have this Types folder.
[00:03:43] And we'll talk about that in a minute, because that's where you're gonna be working the most. This Utility folder has a few things in it, One is gonna be the Schema file. This Schema file, you're gonna see it in a minute, basically, there's only one function in here.
[00:03:55] And what does function does, is it's just gonna load up GraphQL files for us. You don't know what that looks like yet, but you don't have to worry about this. This is just reading the file system and loading up GraphQL files for us, so you don't have to, so we can get to the fun stuff.
[00:04:09] And then there's this odd function here, that also you don't have to concern yourself with. This is basically just some helper methods to help us authenticate with our GraphQL API, and you would do the authentication later. Then we have this DB file, this just handles the connection to our database.
[00:04:26] Again, you don't have to concern yourself with this, just use the Mongoose to connect to our database. Nothing flashy here, and then we have this server file, this is where we're actually creating a GraphQL server. We will be doing a lot of work in here, in our lesson one there is really no a lot going on here.
[00:04:42] You might even see some linting errors that I have in my file. This is where we'll be actually starting or creating our server and get things going. And then an index file's started, so that's just like a little tour of our app. And as far as like the context of the API, what we're gonna be making is.
[00:04:59] We're gonna be making a public API for like an e-commerce app, so think of like a Shopify API that other apps can integrate with. So it's not like the API for our client, it's an API for other developers to integrate with. So it's like a public API for our e-commerce app, so that's the context of the API we're gonna be building.
[00:05:18] So knowing that, if you hop into Types, you'll see three different types here. You'll see like a coupon type, a product type and a user type. The coupon and the user type are pretty much filled out, you won't have to work on either of those. Most of the work you're gonna be doing is gonna be here in the product type.
[00:05:32] There's a few things in here, like a graph QL file, a model, and a resolver. You'll be doing work in here, and most of the tests that you'll be trying to get to pass, will be in here. So we'll be doing this work, the other types, like coupon and user, are just here for you for reference.
[00:05:44] So look at those as references to try to understand what's going on to help you if you're stuck. But we'll be doing most of our work in the product type, last thing is the README, the most important part, I forgot. So yeah, all the resources that I'm talking about, are gonna be here in the README.
[00:05:57] And any instructions for the lessons will be in here, so basically, there's gonna be lessons with numbers on them. I'm gonna give a talk, do some live demonstration and then you'll have an accompanying lesson. That you can check out, too, and start working on the exercises, and then when we come back, I'll give my solution of that lesson.
[00:06:13] And you can follow along, but you can also just check out this solution branch. Which will have the very same or very similar solution that I just live coded. It'll have all the objectives that you need to do for that lesson checked out. Also the test command for each lesson will be listed as well, so only use that test command for that lesson.
[00:06:31] If you use any other test command other than the one for that lesson, you might not get the right test to run. And you might get some that don't work and some that do work. So use that test command for that lesson just to make sure that you're doing the right stuff.