liveBook · Manning

GraphQL

As explained in The Art of Code

A query language and runtime for APIs that lets clients specify the fields they need.

When one endpoint serves several pages, returning every field wastes bandwidth. GraphQL lets each client request only the data it needs, reducing unnecessary payloads. section 8.4.4

Full profile versus report summary

A customer search page may need a complete profile, while a report needs only each customer’s name and order count. Rather than sending the same large response to both, use GraphQL to request the smaller report-specific selection. Dedicated endpoints, lightweight JSON, compression, or compact binary formats provide additional tradeoffs. section 8.4.4

<customer>
  <id>48291</id>
  <name>Emily Doe</name>
  <email>emily.doe@example.com</email>
  <phone>+1-555-0143</phone>
  <address>
    <street>281 Main Street</street>
    <city>Springfield</city>
    <state>CA</state>
    <country>USA</country>
  </address>

  <orders>
    <order>
      <id>10293</id>
      <total>129.90</total>
    </order>
    <order>
      <id>10212</id>
      <total>54.00</total>
    </order>
    <order>
      <id>9912</id>
      <total>260.45</total>
    </order>
  </orders>

  <preferences>
    <newsletter>true</newsletter>
    <language>en-US</language>
    <theme>light</theme>
  </preferences>
</customer>

Inspect the oversized customer payload to identify fields a summary view does not need. section 8.4.4

How The Art of Code covers it

How deep it goes
Explains selective field retrieval as a design technique but stops short of query syntax or runtime implementation.
Examples
Uses a customer profile payload and contrasts full search data with report fields such as name and order count.
What you can do after
Apply GraphQL to request narrower API responses and reduce unnecessary data transfer.
How it connects
Connects API design with endpoints, payload size, JSON, XML, compression, and network traffic.

Also explained in

Compare how 6 books explain GraphQL →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.