GraphcoolDocs
FAQ

Runtime Environment

Last updated a day ago Edit this page

Graphcool Functions can run either inline or using a remote webhook.

#Function context input argument

All functions will be able to access meta information through the context field of the function's input event.

This context has the following structure:

{
  # authentication info
  auth: {
    typeName # if request is authenticated, this is the name of the corresponding type, e.g. `User`
    nodeId # if request is authenticated, this is the `id` of the corresponding node
    token # if request is authenticated, this is the valid authentication token
  },
  # service info
  graphcool: {
    projectId # this will be deprecated shortly, use serviceId instead
    serviceId
    alias
    pat # this will be deprecated shortly, use rootToken instead
    rootToken
  }
}

#Runtime environment for managed functions

Managed functions are deployed to AWS Lambda.

Notice that the maximum execution time of a managed function is 15 seconds.

#Node runtime

Here is a list of supported node versions:

  • Node.js runtime v6.10 (runtime = nodejs6.10)
  • Node.js runtime v4.3 (runtime = nodejs4.3)

#Environment variables

You can provide environment variables to your functions by adding them to the function definition in graphcool.yml under the environment property:

1
2
3
4
5
6
7
8
9
10
11
12
functions:
  # Resolver for authentication
  authenticateCustomer:
    handler:
      # Specify a managed function as a handler
      code:
        src: ./src/authenticate.js
        # Define environment variables to be used in function
        environment:
          SERVICE_TOKEN: aequeitahqu0iu8fae5phoh1joquiegohc9rae3ejahreeciecooz7yoowuwaph7
          STAGE: prod
    type: resolver

Inside the function, you can access it them as follows:

1
const serviceToken = process.env['SERVICE_TOKEN']

See an example for using environment variables inside functions here.

#Webhooks

Functions can also be deployed as webhooks using Function-as-a-Service (FaaS) providers such as Serverless and AWS Lambda, Google Cloud Functions, Microsoft Azure Functions or by hosting the function yourself. Then you need to provide the webhook URL.

Was this page helpful?