Advanced GraphQL, v2

Client Directives: skip & include

Scott Moss

Scott Moss

Superfilter AI
Advanced GraphQL, v2

Check out a free preview of the full Advanced GraphQL, v2 course

The "Client Directives: skip & include" Lesson is part of the full, Advanced GraphQL, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Scott explains what client directives are and presents two kinds of parent directives on the client side. These directives allow users to either skip or include a field in a schema.

Preview
Close

Transcript from the "Client Directives: skip & include" Lesson

[00:00:00]
>> Sorry about client directors. So let me think of a good situation here. So, okay, cool. We can do the user. We do the user. So we got error. We got username. You got created at all. That's all that work. I think that works. Where is that coming from?

[00:00:21]
>> You overrode the error handler at the core level it, with your custom error on the server, formatError.
>> Format, yeah, yeah, yeah, that's it. Let's get rid of that. Cool, it can represent 32, yeah, yeah, no, I'll say that's a string There you go. Okay, cool. All right, so now we got a user.

[00:01:00]
So now we do some client side directors here, some couple client side directors that come for free. So I'll talk a little bit about live queries. You don't see that here. But when that becomes available, you will do something at live, what's really cool, but you can look into that.

[00:01:13]
But the ones I wanna talk about are skip and include. I think those are really cool. So in order to take advantage of that we need to create an operation here. I'm a Korean operation called query. And I was gonna say for get me gonna take in some arguments.

[00:01:26]
I'm just gonna call this argument. Yes, and I'm gonna say it's a Boolean. And it's required. So I'm gonna do that. And then we're gonna say is, I only want to include the airfield if yes, it's true. So I can say include, like this, that takes an argument called if.

[00:01:48]
And you could take a variable like yes, so I'm only gonna include this if Yes, it's true that committed to my query variables. Open this up and argued for Yes, I'm going to say it's false. I'm going to run this and you see errors is gone, because Yes, is false.

[00:02:06]
If Yes, it's true then errors there. So, include is a really good one. And then, skip is the opposite of include. So, skip it if Yes is true. And then don't skip it if Yes is false. So is the inverse. So, skip and include are really good client directives.

[00:02:26]
I've talked about in other GraphQL courses here, a really cool library called Lodash GraphQL. This one looks really cool. You literally can do Lodash queries and your GraphQL. So, I mean, it look pretty good GIF, you can see that's insane. So the possibilities are endless of what you can do with stuff and GraphQL, you can get lost in this real quick.

[00:02:55]
There's also another library of some really helpful ones as well, but I know that those are really cool.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now