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)
There are two ways to handle this on windows.
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.
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, executenpx 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 executeawait prisma.user.findUnique()from inside your Lambda function. And the error would mean thatuseris undefined inside your Prisma Client.From there, my best guess would be that somehow your generated Prisma Client (generated via
npx prisma generateand 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 afterconst app = new PrismaAppSync(...)inside your Lambda function handler. When using VSCode, you should see a Type error appear:If you are using the provided CDK Boilerplate for deployment, it should automatically run
npx prisma generateduring bundling - as long as you have the right setup inside yourschema.prismafile (make sure it wasn’t removed after running theintrospectcommand):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?).