REST API federation by Akamai EdgeWoker Graphql Service with additional Object Caching layber using EdgeKV
there are 3 layers of caching
REST API response will be cached at Edge Server
when data are responded from this cache, you can confirm it from Debug info {cacheHit:EDGE_MEM_HIT or EDGE_HIT etc)
Object data will be extracted from REST API response, and saved to EdgeKV per object id.
Each object has set TTL (shorter than REST API TTL).
this cache will be used to create response to client until it expires TTL
when objects are responded from this cache, you can confirm it from Debug info {cacheHit:KV_HIT)
once Object data is retrieved from EdgeKV cache, then it will be saved in EdgeWorker's memory space.
this cache will be used to create response to client until it expires TTL
when objects are responded from this cache, you can confirm it from Debug info {cacheHit:KV_MEM_HIT)
3 REST API to federate and turn into Single Graphql Service
I have used mockapi servece "My JSON Server" from typecode
Books : https://ewdemo.test.edgekey.net/mockapi/books
Authors : https://ewdemo.test.edgekey.net/mockapi/authors
Publishers : https://ewdemo.test.edgekey.net/mockapi/publishers
Database : https://ewdemo.test.edgekey.net/mockapi/db
Sorce Code : https://github.com/takashito/mockapi
type Author {
id: ID!
name: String!
books: [Book!]!
debug: Debug
}
type Book {
id: ID!
name: String!
publisher: Publisher!
authors: [Author!]!
debug: Debug
}
type Publisher {
id: ID!
name: String!
books: [Book!]!
debug: Debug
}
type Debug {
url: ID!
status: String!
latency: String
cacheable: String
cacheKey: String
cacheHit: String
}
type Query {
authors: [Author!]!
author(id: ID!): Author!
books: [Book!]!
book(id: ID!): Book!
publishers: [Publisher!]!
publisher(id: ID!): Publisher!
}
Now you can access your data with single graphql endpoint.
Routing to rest api to fullfill query will be done by graqhpl engine.
when you hit these example URLs, you may see error due to EdgeWorker initialization timeout, but after hitting URL 2,3 times, it should work.
https://ewdemo.test.edgekey.net/edgekv/graphql?query={book(id:3){name,authors{name},publisher{name}}}
https://ewdemo.test.edgekey.net/edgekv/graphql?query={publishers{name,books{name}}}
https://ewdemo.test.edgekey.net/edgekv/graphql?query={authors{name,books{name}}}
https://ewdemo.test.edgekey.net/edgekv/graphql?query={books{name,authors{name},publisher{name}}}
https://ewdemo.test.edgekey.net/edgekv/graphql?query={book(id:3){name,debug{url,cacheHit,cacheKey},authors{name,debug{url,cacheHit,cacheKey}},publisher{name,debug{url,cacheHit,cacheKey}}}}
https://ewdemo.test.edgekey.net/edgekv/graphql?query={publishers{name,books{name},debug{url,cacheKey,cacheHit}}}
https://ewdemo.test.edgekey.net/edgekv/graphql?query={authors{name,books{name,debug{url,cacheKey,cacheHit}}}}
https://ewdemo.test.edgekey.net/edgekv/graphql?query={books{name,debug{url,cacheHit},authors{name,debug{url,cacheHit,cacheKey}},publisher{name,debug{url,cacheHit}}}}
- url: REST API called by graphql engine
- cacheable: REST API is cacheable or not
- cacheKey: Akamai CacheKey or EdgeKV path
- cacheHit:
- KV_MEM_HIT : Object Data was responded from EdgeKV cache stored in EdgeWorker's Memory space
- KV_HIT : Object Data was responded from EdgeKV cache
- EDGE_MEM_HIT : REST API was responded from Edge memory cache
- EDGE_HIT : REST API was responded from Edge disk cache
- REMOTE_MEM_HIT : REST API was responded from parent memory cache
- REMOTE_HIT : REST API was responded from parent disk cache
- CACHE_MISS : REST API was responded from mock api server (origin)
- sending query via POST will not work due to EdgeWorker limitation