Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to retrieve data with JSON type Postgres #31

Open
Eleven-am opened this issue Apr 15, 2023 · 8 comments
Open

Fails to retrieve data with JSON type Postgres #31

Eleven-am opened this issue Apr 15, 2023 · 8 comments

Comments

@Eleven-am
Copy link

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

@zsnmwy
Copy link

zsnmwy commented Jun 25, 2023

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

@Eleven-am
Copy link
Author

So that means we need to stringify the object once again

@zsnmwy
Copy link

zsnmwy commented Jun 25, 2023

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

@mbrimmer83
Copy link

@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.

@Eleven-am
Copy link
Author

I'd look into it this weekend

@zsnmwy
Copy link

zsnmwy commented Jul 27, 2023

@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.

@zsnmwy
Copy link

zsnmwy commented Jul 29, 2023

@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
Copy link

@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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants