Check out a free preview of the full Server-Side GraphQL in Node.js course:
The "Schemas" Lesson is part of the full, Server-Side GraphQL in Node.js course featured in this preview video. Here's what you'd learn in this lesson:

Scott explains that in order to create a GraphQL server, a schema must first be created using a schema definition language, or SDL, and reviews the basic parts of a schema.

Get Unlimited Access Now

Transcript from the "Schemas" Lesson

>> Scott Moss: All right, so let's hop right into the Schemas and then we'll start writing some code. So the first thing we wanna do is when we create a GraphQL server, is we need to create a schema. So I talked about it a little bit but a schema you have to create what's called a type definitions and you go from there.

[00:00:14] And the way we do that is we use something called a Schema Definition Language, or SDL for short. It'a basically, I think when people think of GraphQL, they think of this. When they say I'm using GraphQL, I'm writing GraphQL, what they're are actually thinking about the language. So the actual syntax that you use to write GraphQL, this is what it is.

[00:00:33] It's called the Schema Definition Language, so we're gonna be using that to create a schema. You can also programmatically create a schema using like the language constructs. So recently JavaScript, there's a GraphQL JavaScript library that allows you to actually use objects and functions to create schemas. That's how it used to be when GraphQL first came out.

[00:00:55] The community kinda moved away from that and they use Schema Definition Language, which is more declarative. But if you're going to be doing dynamic GraphQL queries or GraphQL Schemas on the fly, and really advanced things. You're probably gonna know how to do the programmatic approach of using JavaScript or Ruby or whatever your language is.

[00:01:12] To create a schema versus concatenating strings together, which is really hard. I've done both, and concatenating strings together is way worse than just using functions, so that's that. So now what we're gonna do is, we're gonna use the Schema Definition Language to create some Schemas. So I just wanna talk about some of the base parts, and then we'll hop right into it.

[00:01:33] So some of the basic parts of a Schema, we have Types, and Types are constructs defining a shape with fields. So again, these are very much the same thing as types as you would have in like a type-safe language. Fields are literally keys on those Types that describe what type of value they can have.

[00:01:52] Scalars are a primitive type of value built into GraphQL, and there's different types of scalars and we're gonna go over those. And than you have Queries and Mutations and those are specific types that GraphQL expects you to create. Queries allow you to get data, Mutation allow you to create data.

[00:02:08] And those are basically the basic parts of creating a schema.