serverless / serverless-azure-functions

Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework
MIT License
266 stars 162 forks source link

Can't set output name to `$return` #523

Open alex88 opened 3 years ago

alex88 commented 3 years ago

This is a Bug Report

Description

I'm trying to set the output binding name to $return to use the async function return type, using the code seen in https://github.com/serverless/serverless-azure-functions/pull/308#issuecomment-591517905 (because I couldn't find any documentation of the possible values) it throws an error

It should've changed the out binding name to $return

  api-xml:
    handler: api.getPost
    events:
      - http: true
        route: api/xml
        x-azure-settings:
          direction: out
          name: $return
  Error: Binding not supported
      at Function.<anonymous> (/home/alex/backend/node_modules/serverless-azure-functions/lib/shared/utils.js:113:39)
      at step (/home/alex/backend/node_modules/serverless-azure-functions/lib/shared/utils.js:43:23)
      at Object.next (/home/alex/backend/node_modules/serverless-azure-functions/lib/shared/utils.js:24:53)
      at fulfilled (/home/alex/backend/node_modules/serverless-azure-functions/lib/shared/utils.js:15:58)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.z

Additional Data

It seems that here https://github.com/serverless/serverless-azure-functions/blob/master/src/shared/bindings.ts#L49 displayName is $httptriggerout_displayname while the closest available options are:

  '$httptrigger_displayname',
  '$httpout_displayname',
alex88 commented 3 years ago

Trying with:

  api-xml:
    handler: api.getPost
    events:
      - http: true
        route: api/xml
        name: $return

logs

Serverless: Finished building offline service
Serverless: Spawning process 'func host start'

Azure Functions Core Tools
Core Tools Version:       3.0.3331 Commit hash: 0b57b1647c5a385beb8f7d64fa0e534ad4c7555d 
Function Runtime Version: 3.0.15371.0

[2021-03-08T05:06:59.764Z] The 'api-xml' function is in error: $return bindings must specify a direction of 'out'.
[2021-03-08T05:06:59.824Z] Worker process started and initialized.

which seems to set $return also into the in binding, the temp function folder function.json shows

{
  "disabled": false,
  "bindings": [
    {
      "type": "httpTrigger",
      "direction": "in",
      "name": "$return",
      "route": "api/xml",
      "authLevel": "function"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],
  "entryPoint": "getPost",
  "scriptFile": "../api.js"
}
john-landgrave commented 2 years ago

For anyone else who finds this (possibly related to Apollo server) this comment solves this problem, too. For reference, the solution is:

graphql
  handler: api.graphql
  events:
    - http: true
      methods:
        - GET
        - POST
        - OPTIONS
      authLevel: function
    - http: true
      direction: out
      name: '$return'

@alex88 , if you hadn't figured this out already, there you go.