Hi all, I’m new to Shopify app development, but have experience with TypeScript. I’m trying to create a POS extension app that’s linked to an admin app. I have created the admin app which successfully stores data (productIDs) in a primsa database:
model Product {
id Int @id @default(autoincrement())
globalId String
addedDate DateTime @default(now())
}
export const addProducts = async (productIds: Prisma.ProductCreateManyInput[]): Promise<void> => {
await prisma.product.createMany({
data: productIds,
})
}
I then need to access the data from my POS app. I’ve tried calling the following from my modal:
export const getProducts = async () => {
const products = await prisma.product.findMany();
return products;
}
However I’m getting the following error - Unhandled Promise Rejection: ReferenceError: Can't find variable: global
This is my prisma file:
import { PrismaClient } from "@prisma/client";
declare global {
var prisma: PrismaClient;
}
if (process.env.NODE_ENV !== "production") {
if (!global.prisma) {
global.prisma = new PrismaClient();
}
}
const prisma: PrismaClient = global.prisma || new PrismaClient();
export default prisma;
Am I getting this completely wrong? Is it even possible to access the primsa database from the POS app, or should I be looking at another method? I’ve noticed mentioned of proxies/session tokens in the docs, but really there’s no examples of how this should work. I’d really appreciate a nudge in the right direction! Thanks.