Transcript from the "Subscriptions and GraphQL Services" Lesson
>> Scott Moss: Yeah, subscriptions. So we talked a little bit about earlier what subscriptions were, but we didn't get to them. But subscriptions are basically real-time transport for GraphQL. So think of WebSockets with a GraphQL interface. It's basically what subscriptions are. Luckily for you, GraphQL Yoga, the server that we've been using has subscriptions built into it.
[00:00:22] So all you have to do is figure out like what the transport mechanism is and all the infrastructure as far as GraphQL is pretty much given to you there. So, something to consider if you're gonna be using real-time with GraphQL.
>> Scott Moss: Any questions on any of that stuff?
[00:00:40] No? Okay. This is some of the coolest stuff I wanted to show you that's particular with servers in GraphQL. And it's just like in general things to check out, like going further, more, diving deeper into GraphQL. I recommend looking into what's called persisted queries, I spelled that so wrong.
>> Scott Moss: Persisted queries with GraphQL, which basically, this helps with a lot of stuff. Like caching on the request level. It helps with shortening the request payload for your GraphQL queries, and just making everything easier. So basically a persisted query is like, okay, here's a query that a client sends me it's always gonna be the same.
[00:01:32] So I'm just gonna save that query in the database and I'm just gonna represent it with an ID of one. And then now all the client has to do is do a get request with an ID of one. And I'll grab that query from the database and run it against my GraphQL.
[00:01:45] So it shortens everything, so it shortens the client never has to send up a query. So and then now it's a git request where an idea of one so you can cache that. So there's a lot of things there. So how are they're gonna be checking that out?
[00:01:56] There's more of like a front end optimization, that's why we didn't talk about it today. But you have to implement it on the back end. So if you're building a client, and you wanna speed up things, check that out. Another sweet thing is Apollo Engine, which is basically, as far as I know, wow, they literally just changed this, okay.
>> Scott Moss: Like just today or something. It's one of the only ones I know that uses Apollo's open source GraphQL caching strategy, or I think they call it Apollo Cache, or whatever they call it. Basically, they allow you to define TTLs on fields and types, and what they do is they cache that for you.
[00:02:38] And I think they say it's edge cashing? But as of right now it's not on the edge. I mean on the edge is like a server on a CDN on a note, but it's really not. It's actually like living on your origin. But they cache it for you there, which is really cool.
[00:02:50] So I highly recommend checking that out. I do think they plan on allowing it to be on the edge eventually. But, really cool products, yeah, things like free for a lot of stuff. And they also do performance tracing. So you can go look at the dashboard and see like what resolvers are taking, how long and how you can fix them, and stuff like that.
[00:03:09] So highly recommend checking it out. Setup is not so hard.
>> Scott Moss: Let me think. What else GraphQL-wise? I think that's it. I think that's all I got as far as all the things I can think of off of the top of my head. Now I wanna open it up for questions about anything we did today, anything GraphQL or anything ever.
[00:03:34] Any questions?
>> Student: So, a couple of things I do want to say. So one, all the Apollo stuff is open source. So you can pay Apollo for Apollo engine, and it's super fantastic. But all of the underlying functionality, you can actually, if you want to implement your own tracing.
>> Scott Moss: Right.
>> Student: Stuff you can do that yourself, if you only want to have that on-premises, for example. Also, for persistent queries, one of the benefits is from a security perspective, so it limits the attack surface. So specifically let's say I'm building a website using GraphQL. I'm a malicious hacker and I see your GraphQL server sitting there.
[00:04:26] Instead of being able to make any query, right? You only have the persistent queries that you can use which are already predefined.
>> Scott Moss: Exactly.
>> Student: And the only way that you could modify it would be if you had some variables in there.
>> Scott Moss: Yeah.
>> Student: So you could play with that, but that's-
>> Scott Moss: That's true, yeah.
>> Student: A huge reduction.
>> Scott Moss: That is a huge, I didn't even think of that one, yeah. That's true, I think somebody was trying to hack us last night, I kept getting alerts.
>> Student: Why?
>> Scott Moss: I was like, what is going on? That's crazy, yeah, that's a good one.
[00:04:58] Any other comments, questions?
>> Scott Moss: Everybody's good, so everybody's great with GraphQL now, right? You can go back, convert the whole stack to GraphQL, right? Yeah, you can. You can totally do that. I will say everything you learned today is like more than enough to like do some GraphQL stuff.
[00:05:21] And whatever you don't know you're gonna figure out along the way which is basically how I learned all these stuff. Just, I mean I was using GraphQL since it's been out. So I don't know how long that's been. Couple of years now, and I'm like everything I've learned is just been along the way.
[00:05:36] Just interacting with it, failing, complaining on GitHub and then trying to fix it and then complaining some more. Meeting up with the creators of GraphQL and talking to them and figuring out what they're doing. Just everything that I can to understand this technology. So I recommend just diving in, do a little more with it.
[00:05:54] And you guys can get your hands dirty.
>> Scott Moss: And I think that's it, let me see if I got any questions on here.
>> Scott Moss: In production, would you use GraphQL over Apollo server? Yes, I do use GraphQL at type over Apollo server right now.
>> Scott Moss: Cool.
>> Scott Moss: It looks like we're done here.
[00:06:21] Thanks for coming.
>> Student: [APPLAUSE]