Basic queries are easy to create using the GraphiQLinterface. Queries look like JSON objects without the values and return data in a predictable shape.
- [Instructor] The first place we should get started now is to create our first query. When we build a query, we'll ask for the values of fields on objects. The simplest GitHub query to start with is the viewer field. Now sometimes, when you log into the explorer for the first time, there will be a query preloaded here. You can just delete that and start from scratch. This may have already been loaded up when you loaded the GitHub API here. So, what I want to do is request the viewer field, and then the sub-field I want to request here is name.
So, the viewer, who is this? Well, the viewer is you, whoever is currently logged in is going to be the viewer. Once we have built this query, we're going to hit this play button here. And what this is going to return looks a whole lot like a JSON response. The query here has the exact same same shape as the results. Now, if you return null here for name, it's likely that you don't have a name set up in your GitHub account. You can fix this pretty easily by heading over to GitHub.com, selecting your picture or whatever your avatar is up in the corner, choosing settings, and then from here you can edit your public profile.
Also, a quick note here that queries can have comments. So, if I wanted to add a comment for myself, "first query." All of these are going to start with a pound symbol or hash. So there we go. We've created our first GraphQL query. And in the next video, we're going to take a look at the other fields that are available inside of the viewer object.
In this course, learn how to get started with GraphQL. Eve Porcello walks through the basics of this query language, diving into the data fetching specification, and helping you get up to speed with the syntax and vocabulary of GraphQL. Eve explains how to create basic queries, including how to work with arguments and multiple fields. She also goes into complex techniques for handling data, including working with aliases, fragments, and pagination. Plus, she covers how to edit and transform data with mutations.
- Learning about the origins of GraphQL
- Learning about how GraphQL makes data fetching and updating easier
- Creating basic queries
- Using multiple fields
- Understanding schemas
- Handling data
- Drilling down into nested fields with a query
- Adding variables for argument values
- Creating mutations
- Adding a reaction mutation