Returning specific fields
One of GraphQL’s unique features is how it returns fields in query results. When you make a GraphQL query, it does not return all of the available fields in the results; instead, you include in the query the specific fields you want to return. This can make it easier to get only the data you’re interested in.
For example, in the query below, we are returning the title
and contributors
field. Contributors
is returned a little differently because it’s a nested field, also known as a multivalue field. Here we’re requesting the value
, but we could also return, for example, the kind
subfield to see the type of contributor (author, editor, etc).
{
search(searchterm: "afrofuturism") {
records {
title
contributors {
value
}
}
}
}
Run this query in the GraphQL playground.
Note that you can see in the GraphQL playground shows which fields are nested and what their subfields are. This is also documented in our API reference.