The following is the first few sections of a chapter from GraphQL and Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
Now, let’s see how we can start working with GraphQL from our own Android app.
This chapter’s title refers to “dynamic” GraphQL. And, if you peek ahead to the next chapter, you will see that it refers to “static” GraphQL. That distinction drives the libraries and tools that we can use for making our GraphQL requests.
Sometimes, the GraphQL request that we want to execute is not knowable when we write our app. GraphiQL, for example, allows you to enter in arbitrary GraphQL documents and execute operations from them.
In these cases, we need some code that can take the GraphQL, along with details like the server URL, and execute requests.
Sometimes, the GraphQL representing our request(s) is known when we write our app. Pieces of data that go along with the request might not be known until runtime, though. For example, we might know that we want to find a trip based on a search term, but we do not know the search term until our app’s user types one in on their device.
This is reminiscent of a SQL
that we hard-code into our app, but some of the values to use in the
WHERE clause are based on user input or other runtime values. In
this case, we typically use positional parameters (e.g.,
SELECT * FROM foo WHERE ID=?), so our SQL
SELECT statement can
still be hard-coded, but where we provide the parameter values at
As we saw in a previous chapter, GraphQL offers a similar separation, where we use a separate “variables” bit of JSON for the values that might vary at runtime. This allows us to have our GraphQL document as a plain, unvarying string.
The nice thing about having a GraphQL document as an ordinary string is that if that string is in a nice location — say, a plain text file in our project — we can do more work at compile time to make it easier for us to use that GraphQL.
We will explore all of this and more in the next chapter. The key for now is:
The preview of this section took that left turn at Albuquerque.
The preview of this section may contain nuts.
The preview of this section apparently resembled a Pokémon.
The preview of this section was eaten by a grue.