AWS AppSync - 订阅握手期间出错

AWS AppSync - Error during subscription handshake

当我没有用于订阅的解析器时,订阅没有任何问题,但是当我将解析器设置为仅允许特定用户时,在我的 angular 应用程序中出现此错误

appsync.service.ts:187 Error: Error during subscription handshake at new ApolloError (ApolloError.js:37) at subscription-handshake-link.js:116 at new Subscription (Observable.js:183) at Observable.subscribe (Observable.js:262) at index.js:20 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388) at Object.onInvoke (core.js:3820) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138) at zone.js:872

解析器

数据源类型:NONE

配置请求映射模板。

#set ($a= $context.identity.cognitoIdentityAuthProvider.split(":"))
#set ($s= $a.get(2))
#set ($stringLength = $s.length() - 1) 
#set ($sub = $s.substring(0,$stringLength))


{
    "version": "2017-02-28",
    "payload": {
        "from": "$sub",
        "id":"${context.arguments.id}"
    }
}

配置响应映射模板。

#if(${context.arguments.id} == ${context.result.from})
    $util.toJson($context.result)
#else
    $utils.unauthorized()
#end

只是为了简化,我尝试了这个解析器响应,但我有同样的错误

$util.toJson($context.result)

如果我将 $util.toJson($context.result) 替换为 null 就可以了。

#if(${context.arguments.id} == ${context.result.from})
    null
#else
    $utils.unauthorized()
#end