serverless-azure-functions icon indicating copy to clipboard operation
serverless-azure-functions copied to clipboard

Can't set output name to `$return`

Open alex88 opened this issue 3 years ago • 2 comments

This is a Bug Report

Description

  • What went wrong?

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

  • What did you expect should have happened?

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

  • What was the config you used?
  api-xml:
    handler: api.getPost
    events:
      - http: true
        route: api/xml
        x-azure-settings:
          direction: out
          name: $return
  • What stacktrace or error message from your provider did you see?
  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

  • Serverless Framework Version you're using: 2.28.7
  • Serverless Azure Plugin Version you're using: 2.1.0
  • Operating System: Ubuntu

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 avatar Mar 08 '21 04:03 alex88

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

alex88 avatar Mar 08 '21 05:03 alex88

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.

john-landgrave avatar Jan 17 '22 21:01 john-landgrave