aiji42 / prisma-data-proxy-alt

This is a library to alternate and self-host the Prisma Data Proxy (cloud.prisma.io)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails to retrieve data with JSON type Postgres

Eleven-am opened this issue · comments

Making a request from the client to a table that has a JSON type field throws an error SyntaxError: "[object Object]" is not valid JSON.

Note that a console log at afterMiddleware.ts
below JSON.parse shows the correct data being returned

commented

The JSON-type field needs the string in response, not the Object.

So that means we need to stringify the object once again

commented

I have some testing base on my fork repo.
I added some tests for the JSON field. They passed. And the object has been stringified to string.

https://github.com/zsnmwy/prisma-data-proxy-alt/blob/2b376ac03a94df6058152ed0844ab53579145eec/src/__tests__/query.test.ts#L312-L346

Like:

{
    "data": {
        "findManyProduct": [
            {
// It works
                "skus": "[{\"Url\":\"https://www.x.com.my/-i3677532048-s20852161423.html\",\"SkuId\":20852161423,\"price\":110,\"Images\":[\"https:x/p/de4e4473949b6e15d805096f2ffe22b5.jpg\"],\"Status\":\"active\",\"ShopSku\":\"3677532048_MY-20852161423\",\"quantity\":198,\"saleProp\":{\"color_family\":\"Black\"},\"SellerSku\":\"aw110-Black\",\"tax_class\":\"75586\",\"color_family\":\"Black\",\"package_width\":\"10.00\",\"special_price\":56.19,\"package_height\":\"10.00\",\"package_length\":\"10.00\",\"package_weight\":\"0.1\",\"package_content\":\"1 * One pair of bluetooth headsets1 * Charging case1 * Charging cable1 * User manual\",\"channelInventories\":[],\"fblWarehouseInventories\":[],\"multiWarehouseInventories\":[{\"quantity\":198,\"totalQuantity\":198,\"warehouseCode\":\"dropshipping\",\"occupyQuantity\":0,\"sellableQuantity\":198,\"withholdQuantity\":0}]}]"
            }
        ]
    }
}

But If I use this package in another repo base on Dockerfile, the response is not stringified.
I'm so confused.


Can you reproduce it if you have free time?

I provide some steps for you. Easy and quick.


  1. docker compose -f "docker-compose.yml" up -d --build
image
  1. View Logs - graphql
image
  1. Attach Shell - test
  2. Exec yarn test in the test shell
image 6. View Logs - graphql
prisma:query SELECT "public"."Product"."id", "public"."Product"."attr", "public"."Product"."skus" FROM "public"."Product" WHERE "public"."Product"."id" = $1 LIMIT $2 OFFSET $3
prisma:query COMMIT
Response
{
    "data": {
        "createOneProduct": {
            "id": 2,
            "attr": "{\"a\":123,\"b\":true,\"c\":{\"d\":\"hello\"}}",
            "skus": "[{\"Url\":\"https://www.x.com.x/-x-x.html\",\"SkuId\":20852161423,\"Images\":[\"https://x.net/p/x.jpg\"],\"saleProp\":{\"color_family\":\"Black\"},\"fblWarehouseInventories\":[],\"multiWarehouseInventories\":[{\"totalQuantity\":198,\"warehouseCode\":\"dropshipping\"}]}]"
        }
    }
}
prisma:query SELECT "public"."Product"."id", "public"."Product"."attr", "public"."Product"."skus" FROM "public"."Product" WHERE 1=1 OFFSET $1
Response
{
    "data": {
        "findManyProduct": [
            {
                "id": 1,
                "attr": "{\"a\":123,\"b\":true,\"c\":{\"d\":\"hello\"}}",
                "skus": "[{\"Url\":\"https://www.x.com.x/-x-x.html\",\"SkuId\":20852161423,\"Images\":[\"https://x.net/p/x.jpg\"],\"saleProp\":{\"color_family\":\"Black\"},\"fblWarehouseInventories\":[],\"multiWarehouseInventories\":[{\"totalQuantity\":198,\"warehouseCode\":\"dropshipping\"}]}]"
            },
            {
                "id": 2,
                "attr": "{\"a\":123,\"b\":true,\"c\":{\"d\":\"hello\"}}",
                "skus": "[{\"Url\":\"https://www.x.com.x/-x-x.html\",\"SkuId\":20852161423,\"Images\":[\"https://x.net/p/x.jpg\"],\"saleProp\":{\"color_family\":\"Black\"},\"fblWarehouseInventories\":[],\"multiWarehouseInventories\":[{\"totalQuantity\":198,\"warehouseCode\":\"dropshipping\"}]}]"
            }
        ]
    }
}
  1. The response is correct if you log the response.
image

@zsnmwy What is the state of your fork? It doesn't look like this library is being maintained and might require significant work with the new jsonProtocol.

I'd look into it this weekend

commented

@mbrimmer83

I change to use this repo - https://github.com/zsnmwy/prisma-data-proxy
I fork from https://github.com/OnurGvnc/prisma-data-proxy
And make it works with Prisma 4.x.x. Even the latest version - 4.16.2.
It works well now.

And I create a guide repo to tell you how to use it. Works with any serverless env.


But I did not test with Prisma 5.x.x, especially forjsonProtocol.
I will do some work and make it works with Prisma 4.x.x - 5.x.x.
Based on the official docs, the jsonProtocol improves huge query performance.

commented

@mbrimmer83
Now it supports Prisma 5.0, especially for jsonProtocol.
More detail in repos.
https://github.com/zsnmwy/prisma-data-proxy-windmill-template
https://github.com/zsnmwy/prisma-data-proxy

@mbrimmer83 Now it supports Prisma 5.0, especially for jsonProtocol. More detail in repos. https://github.com/zsnmwy/prisma-data-proxy-windmill-template https://github.com/zsnmwy/prisma-data-proxy

Oh wow, I'm gonna test it out this weekend. I'll let you know how it goes. This is awesome. Thanks!!