Skip to content

Graphql using example with autogenerated schema from code and types

Notifications You must be signed in to change notification settings

mrhitman/graphql-thumbnail

Repository files navigation

Create a GraphQL endpoint with following spec:

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
    	}
    }
  }
}

setup:

  • 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).

challenges:

  1. (primary) thumbnail query and insert_thumbnail mutation works as follows:

    • insert_thumbnail receives a website string input with protocol://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 state url 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 and error_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 and thumbnail query) under:

      urls {
            _256 #url of 256x256 thumbnail
            _512 #url of 512x512 thumbnail
      	}
      
  2. (minor bonus) Files are served using minio.

  3. (big bonus) Add an additional thumbnail Subscription with exact spec with its Query counterpart

    • insert_thumbnail Mutation will immediately return a response with status:processing and upon generation completion it needs to be resolved with status:failed or completed.
    • Subscription will emit complete object on each status change.

remarks:

  • DB usage is not mandatory
  • Puppeteer is your friend.

Installation help info

	// for local env
	cp .env.example .env
	// change .env to your credentials
	yarn install 
	yarn start:dev

	// or using docker
	docker-compose up -d 

About

Graphql using example with autogenerated schema from code and types

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published