aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
507 stars 32 forks source link

custom subscription resolver: connection failed, runtime error #355

Open WJKwok opened 8 months ago

WJKwok commented 8 months ago

What i'm trying to achieve: custom javascript resolver for a subscription.

I understand that when you use appsync and create a type for e.g. type chatMessage { channel: String! userId: String! text: String! id: ID! }

appsync will automatically generate queries, mutations and subscriptions for you. And they work, even though the auto-generated subscriptions all don't seem to have a resolver. Why is that so?

Screenshot 2024-03-15 at 22 07 21

When i try to attach a custom javascript resolver on onCreateChatMessage, it failed with "Connection failed: {\"errors\":[{\"errorType\":\"Code\",\"message\":\"Runtime Error\"}]}".

I tried creating a new subscription, and attached the resolver to it, but it failed too.

The resolver i added was based on the appsync doc

Screenshot 2024-03-15 at 22 14 26 Screenshot 2024-03-15 at 22 16 57

What am i doing wrong? The logs are not showing any errors either :/

cjcatchings commented 7 months ago

I'm facing this same issue with a vanilla schema + DynamoDB data source + Cognito User Pool authentication. I leave the default schema on a new API untouched and add a JavaScript resolver to one of my subscriptions (while adding the necessary @aws_cognito_user_pools annotation to the necessary schema types). I get the same Runtime Error when trying to test the subscription in the console. The same error occurs whether with the generated Resolver JS code from the console or when I replace it with the example code outlined in the documentation:

https://docs.aws.amazon.com/appsync/latest/devguide/aws-appsync-real-time-enhanced-filtering.html

HaaLeo commented 4 months ago

For me it worked once I moved the subscription resolver from the DynamoDB datasource to the NONE datasource.