prisma-archive / graphcool-lib

A convenient tool to use in Graphcool functions to make requests against your Graphcool API
33 stars 6 forks source link

Export FunctionEvent type #11

Closed Grmiade closed 7 years ago

Grmiade commented 7 years ago

It would be great to export the FunctionEvent type in the definition file. To use it to type event parameter.

import { FunctionEvent } from 'graphcool-lib'

export default async (event: FunctionEvent) => {
  await new Promise(r => setTimeout(r, 50))
  return {
    data: {
      message: `Hello ${event.data.name || 'World'}`
    }
  }
}
kbrandwijk commented 7 years ago

Part of a WIP Pull request: https://github.com/graphcool/graphcool-lib/pull/9/commits/89322a6629fd8304552700bba881657d17451f0f

marktani commented 7 years ago

It has been released in 0.1.0: https://github.com/graphcool/graphcool-lib/releases/tag/v0.1.0 🙂 Note that you need to specify the generic parameter for the event data:

export default async (event: FunctionEvent<any>) => {
  await new Promise(r => setTimeout(r, 50))
  return {
    data: {
      message: `Hello ${event.data.name || 'World'}`
    }
  }
}

or

interface EventData {
 name: string
}

export default async (event: FunctionEvent<EventData>) => {
  await new Promise(r => setTimeout(r, 50))
  return {
    data: {
      message: `Hello ${event.data.name || 'World'}`
    }
  }
}