This course has been updated! We now recommend you take the Server-Side GraphQL in Node.js course.
Transcript from the "What is GraphQL?" Lesson
>> Scott Moss: So what is GraphQL? Raise your hand if you used GraphQL before.
>> Scott Moss: One person, okay, when you say you used it, Mark, did you use it as a consumer querying a GraphQL API or did you use it building a GraphQL API?
>> Speaker 2: Building GraphQL API.
>> Scott Moss: Okay, so you have some experience.
[00:00:17] Anybody else have experience querying a GraphQL API server? It's gonna be fun, okay. A lot of learns today, a lot of learns. All right, so GraphQL is basically, it's a strongly typed query language and runtime for your data. It's kind of this new, not only is it like a new technology, it's sitting in a new place where it's like, you think of like REST as like a way to build an API.
[00:00:46] In fact, it is your API, GraphQL sits in front of your API and your request. So you can still have an API underneath GraphQL as well, so it's like a different place in the stack of how you retrieve data from the server. And as we go along the course, you'll see what I'm talking about.
>> Scott Moss: So it's open source and it's created by Facebook. And when I say it, GraphQL itself, it's just a spec. GraphQL is actually just a spec. When I say it, I'm talking about the spec. So Facebook created the spec for GraphQL and what it can, and what it should, and what it won't do.
[00:01:41] And that spec is constantly growing, and those tools are constantly being updated. So, yeah, Facebook created that spec. They used it internally for a couple years, and then they decided to open source it.
>> Scott Moss: Basically, GraphQL gives clients the power to describe exactly the data that they want.
[00:02:00] So basically, if I'm an application or if I'm a developer and I want to grab a user, but I only wanna get the first name and the last name, how would I do that with REST? If I'm saying give me the user, but only the first name and last name, well, with REST, technically, you can't do that.
[00:02:19] So what you would have to do in your API is you would have to accept query parameters. So somebody could attach on a query string at the end of it and say first name true or last name true or whatever. And then you would have to do that, but then you open yourself up to all different types of vulnerabilities and stuff like that.
[00:02:35] So you have to go beyond REST to do that, and you have to manly do that for every single field in your database, whereas GraphQL automatically does that for you. And the client only gets back what they want, nothing more, nothing less.
>> Scott Moss: It's strongly typed, so the way I like to think of it, is it's like typescript for your API.
[00:02:55] So imagine if you can write TypeScript types and interfaces and stuff like that, for your API. That's what GraphQL is like. It's the same thing. If any of those type validations fail, your API request fails, so it's pretty cool.
>> Scott Moss: It enables excellent developer tooling and experiences. Because it is strongly typed, like TypeScript, you get some really good dev tools.
[00:03:19] Some autocomplete features, a whole bunch of smart tooling where you can mock data out. As you will see, we'll use this tool that allows us to interact with our graphical API. And we can get automatic documentation for it, all types of certain things, because everything is strongly typed.
[00:03:34] It's a finite API that you're creating so that you can kind of understand what's happening. So yeah, the tooling for GraphQL is legit, and it keeps growing. There's literally a new GraphQL thing everyday. I mean, there's literally companies built around just GraphQL. So yeah, tooling is great, and it's always getting better.
>> Scott Moss: And like I said, it can sit in front of any existing API because it's just a query language. It's not actually the API itself. It's just how you query an API. So there's nothing stopping you from putting GraphQL in front of a REST API, in front of another GraphQL API, in front of anything that you want.
[00:04:15] It just sits in front of it. It's just a query language to describe how you interact with that API. And if that doesn't make sense, as we start building it, you'll see what I'm talking about. Any questions so far?
>> Speaker 2: Just it can go both ways? So you can query and you can save data, the same?
>> Scott Moss: Yes, so you can read and you can write.
>> Speaker 2: Okay, okay, okay, I'm thinking this could be more structure behind it and you can actually make delegate it to maybe.
>> Scott Moss: Yeah.
>> Speaker 2: Okay.
>> Scott Moss: Yep, you could definitely do that and we'll talk about it. So the word query, I'm gonna say the word query a lot today and it's gonna mean different things.
[00:04:51] So I'm gonna try to elaborate when I say the word query of which type of query I'm talking about.