prisma-appsync icon indicating copy to clipboard operation
prisma-appsync copied to clipboard

Subscriptions via AWS AppSync console gives an error

Open harsh-13799 opened this issue 1 year ago • 2 comments

I am encountering errors when using the default subscription generated by the prisma-appsync package in the AWS AppSync console.

Error with Default Subscription

When trying to use a subscription, I receive the following error:

{
    "errors": [
        {
            "message": "Connection failed: {\"errors\":[{\"errorType\":\"Error\",\"message\":\"{\\\"error\\\":\\\"sa[s.context.action] is not a function\\\",\\\"type\\\":\\\"INTERNAL_SERVER_ERROR\\\",\\\"code\\\":500}\"}]}"
        }
    ]
}

I found that if I manually update the subscription resolver to use <resourceName>NoneDataSource, the subscription works without errors. However, this manual change is reset after each deployment, which is not ideal.

Attempt to Use none DataSource

To avoid manual updates, I tried modifying(by extending and tweaking schema.prisma) the resolvers.yaml file to use datasource: none instead of datasource: prisma-appsync for subscriptions. However, running yarn dev results in the following error:

\node_modules\amplify-appsync-simulator\lib\resolvers\unit-resolver.js:12
            throw new Error(`Invalid config for UNIT_RESOLVER ${JSON.stringify(config)} \n ${e.message}`);
                  ^

Error: Invalid config for UNIT_RESOLVER {"typeName":"Subscription","fieldName":"onCreatedFile","dataSource":"none","dataSourceName":"none","kind":"UNIT","requestMappingTemplateLocation":"lambdaRequest.vtl","responseMappingTemplateLocation":"lambdaResponse.vtl"}
 Missing data source none
    at new AppSyncUnitResolver (\node_modules\amplify-appsync-simulator\src\resolvers\unit-resolver.ts:12:13)
    at \node_modules\amplify-appsync-simulator\src\index.ts:106:15
    at Array.reduce (<anonymous>)
    at AmplifyAppSyncSimulator.init (\node_modules\amplify-appsync-simulator\src\index.ts:98:49)
    at Object.start (\node_modules\prisma-appsync\dist\server\index.js:22:3466)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Proxy.createServer (\node_modules\prisma-appsync\dist\server\index.js:22:4301)

Questions

  1. If I decide to use datasource: prisma-appsync for subscriptions to avoid manual updates, what changes are required to fix the first error ("sa[s.context.action] is not a function")?
  2. Is it valid to use datasource: none for subscriptions by extending the schema? If so, how can I resolve the Invalid config for UNIT_RESOLVER error?

If further details are needed, I’m happy to provide them. Thank you in advance for your help!

harsh-13799 avatar Nov 15 '24 13:11 harsh-13799

Hey @harsh-13799 thanks for the detailed report!

You've indeed spotted a bug with the generator, and I was able to reproduce it on my end. You're right that datasource: none should be the default setting for all subscriptions, but it currently isn't. I'll make sure to fix this in the next patch release.

Regarding your "Attempt to Use non Datasource" error, it seems to relate to the amplify-appsync-simulator package, which we use for running AWS AppSync locally. Are you experiencing a similar issue when it's deployed on AWS, or is it only happening locally?

To sum up, I'll look into the issue and aim to release a patch, though I can't provide an exact timeline right now as I’m quite busy with work.

maoosi avatar Nov 18 '24 07:11 maoosi

Thanks for your response, @maoosi!

Regarding the "Attempt to Use none Datasource" error, it seems to occur specifically during local testing. Since it’s not functioning correctly locally, I haven't been able to proceed with deploying it on AWS.

harsh-13799 avatar Nov 18 '24 09:11 harsh-13799