5 Data Focused API

 

This chapter covers

  • What can cause accountants to run amok
  • That in some cases, clients are interested in the data from a microservice, not a business action
  • How to use Faceted Search to solve some data query requirements in a REST or RPC API
  • Why GraphQL was created specifically for microservices that need to provide a data query interface
  • How to define a GraphQL Schema
  • GraphQL operations, including Queries, Mutations, and Subscriptions
  • How a client creates a GraphQL query
  • What are GraphQL Resolvers and how do they work?
  • GraphQL and API Versioning
  • Pros and Cons of GraphQL

Oh boy, I just got a call from Bullwinkle. He was screaming – he had just been attacked by a rabble of crazed accountants, rushing at him with their sharpened pencils whipped out from their pocket protectors. Real horrific - I get chills just thinking about it.

I asked him what got his accountants so riled up, as most accountant I know are pretty docile after their morning coffee. Well, it all had to do with our Fantler Store microservice. As you probably remember, that microservice is part of the subdomain the Accounting department cares about.

5.1 Business APIs vs Data APIs

At first I couldn’t see what was causing all the mayhem. The Fantler Store microservice (figure 5.1) is pretty simple. It has one entity, Transaction, and one responsibility – Complete Sale.

Figure 5.1 FantlerStore microservice

5.2 Faceted Search to Consolidate Data Queries

5.3 What is GraphQL and Why Do We Care?

5.4 GraphQL – the Unexpected Twist

5.5 GraphQL Schema

5.6 GraphQL Operations

5.7 Specifying and Customizing GraphQL Calls

5.8 Implementing GraphQL

5.8.1 GraphQL Resolvers

5.8.2 API Versioning

5.9 Final Thoughts on GraphQL

5.10 Summary