This course has been updated! We now recommend you take the Advanced GraphQL, v2 course.

Check out a free preview of the full Advanced GraphQL course:
The "GraphQL API Recap" Lesson is part of the full, Advanced GraphQL course featured in this preview video. Here's what you'd learn in this lesson:

Scott shows how to use graphql-yoga node module to get the GraphQL server up and running. Given a GraphQL Schema, you will need to create a server the correctly allows a query and mutation based on the schema.

Get Unlimited Access Now

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.

[00:02:29] If you go online and you look at resources, you'll see people writing their schemas in JavaScript. You'll see them using a package from GraphQL. I don't think a lot of people do that anymore. Unless you're doing really advanced stuff, if you're doing like code generation and meta programming, yeah, for sure.

[00:02:49] But most people use raphQGL files cuz it's a lot more expressive to use than a schema definition language, and a GraphQL file and justimport it as a string on the back end. So that's what we're gonna do. But again if you go look, you might see people creating their schemas using JavaScript.

[00:03:04] I think that's a lot more complicated. And that's kind of how it was when GraphQL first started. In today's world not so much. So I recommend not doing that unless you're doing like crazy stuff, which we do. And we do use the JavaScript on sometimes for crazy stuff.