Interacting with GitHub's GraphQL API
In this lesson, we are now finally ready to interact with GitHub's GraphQL API.
There are two common ways to interact with the GitHub GraphQL API without writing any source code for it.
First, you can use GitHub’s GraphQL Explorer. You only need to sign up with your GitHub account to perform a query or mutation to their GraphQL API, and it’s a good way to simplify your first experience.
Second, you can use a generic client in the form of an application. GraphiQL is a client that makes GraphQL requests as integration or as a standalone application. The former can be accomplished by setting up GraphiQL directly in your application; the latter may be more convenient for you by using GraphiQL as a standalone application. It’s a lightweight shell around GraphiQL that can be downloaded and installed manually or by the command line.
GitHub’s GraphQL Explorer knows about your credentials since you need to sign up using it, but the GraphiQL application needs to know about the personal access token you created. You can add it in your HTTP header for every request in the headers configuration.
You can add a new header with a name and value to your GraphiQL configuration. To communicate with GitHub’s GraphQL API, fill in the header name with “Authorization” and the header value with “bearer [your personal access token]“. Save this new header for your GraphiQL application.
Finally, you are ready to make requests to GitHub’s GraphQL API with your GraphiQL application.
If you use your own GraphiQL application, you’ll need to provide the GraphQL endpoint (URL in this case) for GitHub’s GraphQL API: https://api.github.com/graphql.
For GitHub’s GraphQL API, use the POST HTTP
method for queries and mutations, and to transfer data as a payload to your GraphQL endpoint.
This lesson taught you two ways to interact with GitHub’s GraphQL API. While GitHub’s GraphQL Explorer can only be used for GitHub’s API, GraphiQL integrated into an application or standalone can be used for any GraphQL API. The difference is that it requires a bit more setup.
The GitHub GraphQL Explorer is really nothing more than a hosted standalone GraphiQL application tailored to use GitHub’s GraphQL API.
Now that we’ve set up to use the GraphQL API, we are ready to implement our first GraphQL client interactions. See you in the next chapter!
Get hands-on with 1200+ tech skills courses.