-
Book Overview & Buying
-
Table Of Contents
The Spring Pocket Guide
By :
REST works well, and it’s a boon for the open web, but it’s not necessarily the most useful (or efficient) protocol in which to build homogenous services. I think the honor of most useful goes to GraphQL.
GraphQL was developed at Facebook (now Meta) in 2012 and publicly released in 2015 with a specification, a reference implementation in JavaScript (the bad kind), and the GraphiQL in-browser console. It was born out of frustration with the limitations of REST APIs, especially in the context of mobile applications, where over-fetching and under-fetching data were common problems.
It requires some schema. Let’s define some types mapping more or less to our Dog type, and a read operation (a query) and a write operation (a mutation):
--src/main/resources/graphql/schema.graphqls
type Dog {
id :Int
name: String
owner: String
description: String
shelter: Shelter
}
type Shelter {
city: String
}
type Query {
dogs :[Dog]
...