This document summarizes different approaches for retrofitting GraphQL APIs: writing a GraphQL layer by hand ("The Developer Way"), using a lightweight API gateway ("The Cloud-native Way"), and using cloud provider native serverless services ("The Serverless Way"). It assesses the key criteria of convenience, rate limiting, query depth limiting, and caching for each approach. It includes code samples and a demo of setting up a GraphQL API with an API gateway.
3. Agenda
Why GraphQL?
The Developer Way: Writing a GraphQL API layer by hand
The Cloud-native Way: Using a lightweight API gateway
The Serverless Way: Using Cloud Provider native services
Conclusion and Q&A
4. What is it?
Query Language for APIs
and runtime to fulfill this queries
with existing data
Why do we want it?
Clients can dynamically define
the structure of required data,
which is then returned by the
server.
Over-fetching and under-fetching
are history!
Does it work?
Stay tuned :)
https://graphql.org/
5. Ask for what you want:
No more under-fetching or over-fetching
sessionId
sessionTitle
speakerLastName
sessionId
sessionTitle
firstName
lastName
currentLocation
phone
/sessions
/speakers/{speaker-id}
/schedule
Use Case 1:
● aggregate
● select only relevant attributes
● rename
6. Ask for what you want:
No more under-fetching or over-fetching
sessionId
sessionTitle
speakerLastName
sessionId
sessionTitle
firstName
lastName
currentLocation
phone
/full-schedule
/schedule-for-my-use-case
dateOfBirth
favoriteDish
shoeSize
Use Case 2:
● select only relevant attributes of
large API
11. “The Developer Way”: Directly offering a GraphQL API using Quarkus
■ Initial situation: two seperate APIs for sessions and speakers at the conference
■ Idea: We implement a GraphQL-Endpoint providing and combining all the information
GET /sessions
[{
id: 1
title: “abc”
speaker: [1,2]
…
}]
GET /sessions/{id}
…
GET /speakers
[{
id: 1
firstName: “Bill”
lastName: “Gates”
…
}]
GET /speakers/{id}
…
GET
/sessions/speaker/{id}
[{
title:
…
}]
12. Alternatives Assessment for retrofitting options:
Key Criteria for today:
Convenience Rate Limiting
Query Depth
Limiting
Caching
14. ■ API Gateways
– are already widely used for several use
cases like routing, authentication, …
■ GraphQL API Gateways can
– provide a single schema for several
microservices
– enhance APIs of services who are not
capable of GraphQL directly
– enable clients to query a combination of
available data without having to know
about the service architecture
GraphQL via API Gateways
Ernie GraphQL
Service
Bert Restful
Service v1
Bert Restful
Service v2
GraphQL API
Gateway
15. Demo with Tyk
■ We will setup a Graph QL API with Tyk (tyk.io)
■ Tyk offers an open source API gateway, we are using the
“self-managed” version (requires a license), as the open
source version is fairly limited regarding comfort
https://tyk.io/docs/tyk-on-premises/
Schedule +
Session Service
Tyk API
Gateway
16.
17.
18.
19.
20. Alternatives Assessment for retrofitting options:
Key Criteria for today:
Convenience Rate Limiting
Query Depth
Limiting
Caching