Graph.cool Functions - Chromeless

framework

#1

Hey there!

I am having a hard time getting graph.cool functions to run, with chromeless.

Background: I want to generate social media sharing images. As I am using graph.cool for my backend I thought this might be a good job for Chromeless.

I deployed chromeless to my personal aws account with the serverless config. So far so good.

Now I want that if a user creates a new “post” in my case a new color palette, that the function gets invoked and chromeless taking a screenshot of of a “private” page which is only for generating the images.

However I can not get it working. I tried it with operationAfter hooks, however as they run sync, its quite a bad experience and I am getting a timeout in the logs. (I guess because of cold boot time of lambda)

So I switched to subscriptions. However now, the functions never gets invoked.

graphcool.yml

functions: 
  createThumb:
    type: subscription
    query: src/thumbnail/newPalette.graphql
    handler:
      code:
        src: src/thumbnail/createThumb.js

newPlatte.graphql

subscription {
  Palette(filter: {
    mutation_in: [CREATED, UPDATED]
  }) {
    node {
      id
    }
  }
}

createThumb.js

const { Chromeless } = require('chromeless')
const { fromEvent } = require('graphcool-lib')

async function run (id) {
  const chromeless = new Chromeless({
    remote: {
      endpointUrl: 'https://xxxxxx.execute-api.eu-west-1.amazonaws.com/dev/',
      apiKey: 'xxxxxxxx',
    },
  })
  const screenshot = await chromeless
    .goto(`https://www.colourhunt.com/image/${id}/`)
    .wait('.Seo_card')
    .screenshot()

  console.log(screenshot)
  await chromeless.end()
}

export default async event => {
  const { id } = event.data.Palette.node

  console.log('📝 ID:: ', id)
  console.log('📸 Creating screenshot')
  const screenshot = await run(id)

  console.log('📸', screenshot)
  return screenshot
}

Would be awesome if someone could point me into the right direction