Search code examples
angularamazon-web-servicesgraphqlapolloaws-appsync

AWS AppSync - Error during subscription handshake


When I have not resolver for subscription I dont have any problem with subscription but when I set the resolver to allow only specific users, in my angular App I have this error

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

Resolver

Data source type: NONE

Configure the request mapping template.

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

Configure the response mapping template.

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

Only for simplify, I tried this resolver response but I had same error

$util.toJson($context.result)

Solution

  • If I remplace $util.toJson($context.result) for null work fine.

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