query getThumbnails($id: string!) {
thumbnail(id: $id) {
id:int
created_at:int //timestamp
status:String //processing|completed|failed
error_message:String //not empty when `status` value is `failed`
error_code:int //not empty when `status` value is `failed`
website:String //url
urls {
_256:String //url
_512:String //url
}
}
}
mutation addThumbnails($website: String) {
insert_thumbnail(objects: {website: $website}){
returning {
id:int
created_at:int //timestamp
status:String //processing|completed|failed
error_message:String //not empty when `status` value is `failed`
error_code:int //not empty when `status` value is `failed`
website:String //url
urls {
_256:String //url
_512:String //url
}
}
}
}
- Code is written in Typescript.
- Solution is dockerized. ( setup is described with a
Dockerfile
). - Runnable with docker compose ( there is
docker-compose.yaml
to run).
-
(primary)
thumbnail
query andinsert_thumbnail
mutation works as follows:-
insert_thumbnail
receives awebsite
string input withprotocol://domain.tld
format and makes a PNG screenshot out of it. -
status
represents thumbnail generation status. status can have following values:processing
: thumbnail is being generated. in this stateurl
values are empty as processing is still ongoing. For current challenge,insert_thumbnail
mutation is synchronous and only returns a value after generating thumbnail attempt is done. So in practice, we should NOT see this value at all.completed
: thumbnail generation finished successfully. now ´url´ should have thumbnails with corresponding resolution.failed
: thumbnail generation has failed.error_message
anderror_code
needs to be set.(these fields can be random even. It does not matter much)
-
Screenshots are served as static files and their urls returned to client(via
insert_thumbnail
mutation andthumbnail
query) under:urls { _256 #url of 256x256 thumbnail _512 #url of 512x512 thumbnail }
-
-
(minor bonus) Files are served using minio.
-
(big bonus) Add an additional
thumbnail
Subscription with exact spec with its Query counterpartinsert_thumbnail
Mutation will immediately return a response withstatus
:processing
and upon generation completion it needs to be resolved withstatus
:failed
orcompleted
.- Subscription will emit complete object on each
status
change.
- DB usage is not mandatory
- Puppeteer is your friend.
// for local env
cp .env.example .env
// change .env to your credentials
yarn install
yarn start:dev
// or using docker
docker-compose up -d