prisma-appsync: Some queries are returning errors

I’m using this prisma-appsync to deploy GraphQL API to lambda and AppSync using my existing PostgreSQL database. Some queries are returning errors while executing. I’m using the command introspect initially to get prisma.schema based on the database.

ERROR	Invoke Error 	{
    "errorType": "TypeError",
    "errorMessage": "Cannot read property 'findUnique' of undefined",
    "stack": [
        "TypeError: Cannot read property 'findUnique' of undefined",
        "    at ut.get (/var/task/prisma/generated/prisma-appsync/client/index.js:2:72228)",
        "    at async $s.resolve (/var/task/prisma/generated/prisma-appsync/client/index.js:2:76727)",
        "    at async Runtime.exports.handler (/var/task/index.js:18:18)"
    ]
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

There are two ways to handle this on windows.

  1. if you have git bash, use that for the cli to install and deploy
  2. Use WSL ubuntu2 for the install and deploy (ubuntu will need a change to the prisma client file names in the cdk file) https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference/#binarytargets-options

Docker bundling is not required for CDK. You can run it without and get the same outcome, if it throws any errors, as I remember inside the AWS CDK code its looking if “esbuild” is installed to skip docker build.

One more thing is, in file cdk/index.ts line no 122 forceDockerBundling: true is causing issues if there is no docker installed in local system. If the local system OS is windows, some commands like cp rm in the same above mentioned file also causing issues for command cdk deploy

Resolved in 1.0.0-beta.58.2 (Fix: Issue linked to Prisma models naming").

Thanks @ViVa98 that helps a lot! I’ve started working on a fix, that consist of generating a new mapping config, for Prisma-AppSync to be able to keep track of original Prisma Client model names.

It will be included with the next Beta release.

When using Docker for bundling, the commands inside commandHooks (cdk/index.ts line 101) are to copy your schema at the right place inside the running Docker instance, execute npx prisma generate (to make sure your schema and AppSync files are in sync) and bundle your Lambda function with the correct runtime libraries and Prisma Client.

If you had to change some of these to work locally on Windows, then it is possible that Prisma Client is not compiled/bundled properly because of it. I am working on mac, so it will be hard for me to help with this. Are you able to install and run Docker on your machine instead?

Hey @ViVa98. From the error message, it seems like it is failing when trying to execute a get operation against a particular model (see source code here).

Prisma-AppSync Client act as a wrapper around Prisma Client, so assuming you were trying to query getUser, the underlying method is trying to execute await prisma.user.findUnique() from inside your Lambda function. And the error would mean that user is undefined inside your Prisma Client.

From there, my best guess would be that somehow your generated Prisma Client (generated via npx prisma generate and deployed with your Lambda function) would be out-of-sync with the GraphQL Schema and Resolvers Config currently deployed on your AppSync instance.

To confirm this is indeed the issue, you can try to insert app.prisma.user (replacing user with your failing model name) just after const app = new PrismaAppSync(...) inside your Lambda function handler. When using VSCode, you should see a Type error appear:

Property ‘user’ does not exist on type ‘PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation>’.ts(XXX)

If you are using the provided CDK Boilerplate for deployment, it should automatically run npx prisma generate during bundling - as long as you have the right setup inside your schema.prisma file (make sure it wasn’t removed after running the introspect command):

generator client {
    provider = "prisma-client-js"
    binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

generator appsync {
    provider = "prisma-appsync"
}

Let me know if that help you figure out the issue?

If not, please share your Prisma Schema (removing sensitive data, if any) and more details around your setup and deploy process (e.g. Are you using AWS CDK and the provided boilerplate to deploy your API?).