Advanced GraphQL GraphQL API Recap
This course has been updated! We now recommend you take the Advanced GraphQL, v2 course.
Transcript from the "GraphQL API Recap" Lesson
>> Scott Moss: All right, so what I'm gonna do is, I'm just gonna go over kind of how I build a GraphQL API in the tools and packages that I use cuz there's so many of them. We're just gonna get something going and we're just gonna just try to query something.
[00:00:13] And we're just gonna go through all the pieces, and how they go together just so we can get something that we can query and execute. Okay, so the first thing is as far as the technologies, or the packages that I use to create my GraphQL APIs today. I'm using this package called GraphQL Yoga.
[00:00:33] Anybody ever heard of that? It's pretty legit. So it's made by the, I guess they're Prisma now, but they used to be GraphCool. It's made by them and it's basically an abstraction around Apollo, GraphQL, Express GraphQL. It's like an abstraction around that and they kind of did a good job of just, here's everything you need to make a GraphQL server.
[00:00:53] So this is new, this wasn't a thing last time I taught GraphQL. So this stuff is changing all the time, but this is what I use in production. But just to get going, basically there's gonna be two parts to a GraphQL server, if you've never used GraphQL. You have your schema definition language, and then you have what's called resolvers.
[00:01:14] Anybody want to tell me what resolvers are? I'll pick on somebody.
>> Scott Moss: Resolvers, what are resolvers?
>> Speaker 2: They take the query and actually do the DB queries and give you the result that you're looking for.
>> Scott Moss: Right, they resolve the data. Exactly right, that's why they're called resolvers.
[00:01:33] All right, the first thing though is we need to create some definitions, we actually need to create a schema for GraphQL. GraphQL is a type-based, thin layer over an API. So if you could think about it like this, it's basically Typescript for your API. It itself is not your API, the definition language is not, but it describes how your API will look.
[00:01:57] What the data looks like, what the type of data it is, and how you can access it. It's a description of that. And then it's up to you to resolve that data in whatever means necessary. So in order to do that we actually have to write that schema, those types, those shapes, and then we have to stick to it and resolve it.
[00:02:13] So that's the first thing we're gonna do today. So the biggest part is when you actually write your GraphQL schema there's a couple ways you can do it. I like to use a GraphQL file. You can use .graphql or .gql, and that's kind of like how I like to write mine.