The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


GraphQL in Five Minutes

Before we get into what GraphQL is, why you might be using it, and what it has to do with Android, let’s spend a few minutes playing around with GraphQL. One of the nice things about this piece of technology is that you can experiment with it easily enough, using publicly-available GraphQL sites… starting from the comfort of your desktop Web browser.

(you could use a mobile Web browser, such as on your Android phone or tablet, but a physical keyboard is really handy when working on programming-like tasks)

Step #1: Gotta Get a GraphiQL

Developers love tools. After all, programming computers by hand-calculating machine instructions for a CPU gets to be tiresome rather quickly. We are used to having IDEs for base development, with structured editors, debuggers, and the like. We are used to having databases with clients that we can use for testing queries. We are used to being able to browse the source of Web pages and bring up other interactive Web development tools in the browser.

The people who created GraphQL provided a Web-based interactive GraphQL tool called GraphiQL. GraphiQL allows you to play around with GraphQL without having to install anything or even know much about GraphQL.

With that in mind, in a desktop Web browser, visit https://graphql-demo.commonsware.com/0.2/graphql. While this link will work on a phone or tablet, GraphiQL is not designed for use from mobile devices.

This will bring up GraphiQL on a CommonsWare-hosted GraphQL-powered server:

GraphiQL, As Initially Launched
Figure 1: GraphiQL, As Initially Launched

On the left, you can enter in something in GraphQL. Clicking the “run” button (rightward-pointing triangle) sends that to the server, which triggers a response on the right.

Step #2: Drafting a Document

So, on the left, type in:

{
  allTrips {
    id
    title
  }
}

You will notice that as you start typing, GraphiQL will offer a code-completion popup:

GraphiQL, Showing Code-Completion Popup
Figure 2: GraphiQL, Showing Code-Completion Popup

Similarly, if you get part-way through — just entering in the allTrips bit without its own set of braces — you will see that the allTrips gets a red under-squiggle, indicating an error that you can view by hovering your mouse over it:

GraphiQL, Showing Error Popup
Figure 3: GraphiQL, Showing Error Popup

As a result, this feels a bit like working in an IDE like Android Studio.

This is all possible because GraphiQL knows some stuff about the data being published via GraphQL from the server. We will come back to that point in a bit.

Step #3: Making the Request

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

Step #4: Looking at the Docs

The preview of this section is presently indisposed.