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
The JSON-type field needs the string in response, not the Object.
So that means we need to stringify the object once again
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.
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.
docker compose -f "docker-compose.yml" up -d --build
![image](https://private-user-images.githubusercontent.com/35299017/248594248-9228cba1-711e-4c1b-89bc-07dbfe9c3d10.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI2NzQwMzUsIm5iZiI6MTcyMjY3MzczNSwicGF0aCI6Ii8zNTI5OTAxNy8yNDg1OTQyNDgtOTIyOGNiYTEtNzExZS00YzFiLTg5YmMtMDdkYmZlOWMzZDEwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODAzVDA4Mjg1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI1MjdmMTllYTU3NzRlMjcxNDdlNTFhNmFhMTYzNzgwMmM4MzdjZDI4MTRkMTZkODlhOGE1MmNkMGNhODg4MzgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.E9Z0Xlohj-rxoFW0haYAdNFcLUEjQKMdLGJnQgcWUtQ)
- View Logs - graphql
![image](https://private-user-images.githubusercontent.com/35299017/248594575-c108b216-4f59-4297-97b7-4239eb217414.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI2NzQwMzUsIm5iZiI6MTcyMjY3MzczNSwicGF0aCI6Ii8zNTI5OTAxNy8yNDg1OTQ1NzUtYzEwOGIyMTYtNGY1OS00Mjk3LTk3YjctNDIzOWViMjE3NDE0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODAzVDA4Mjg1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTIyYjliNDEzMmIwMTUxNWI5YmUxYjViMjM4MzBjMzZhN2IxOWMyMGY0ZDZiMWI4ZTk1MjAyNTIwZmFiMmMzOTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.DG7S0Dbqt6WKuxgoiVWhMY_McxokRv5hVVkgZC-0x3s)
- Attach Shell - test
- Exec
yarn test
in the test shell
![image](https://private-user-images.githubusercontent.com/35299017/248594591-1cddbbc7-a4b5-4c5d-83d6-cd6d9e7f1288.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI2NzQwMzUsIm5iZiI6MTcyMjY3MzczNSwicGF0aCI6Ii8zNTI5OTAxNy8yNDg1OTQ1OTEtMWNkZGJiYzctYTRiNS00YzVkLTgzZDYtY2Q2ZDllN2YxMjg4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODAzVDA4Mjg1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQxMDI2NGJhNTEyMTRhMTU2MTRlYWRiYjRhNmQ4OTcyODJhYzZkNDVkMDYzYTkyZWM2OTdhMTIzMTE2ZTI1ODcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.kdu3GiTIHRqV70vrOeeInKcpXnj0bHLT1crlytH52IQ)
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\"}]}]"
}
]
}
}
- The response is correct if you log the response.
![image](https://private-user-images.githubusercontent.com/35299017/248594739-b9711732-2ed9-4a82-bf8d-ead1f1c7a2f3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI2NzQwMzUsIm5iZiI6MTcyMjY3MzczNSwicGF0aCI6Ii8zNTI5OTAxNy8yNDg1OTQ3MzktYjk3MTE3MzItMmVkOS00YTgyLWJmOGQtZWFkMWYxYzdhMmYzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODAzVDA4Mjg1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQxNGZmN2RiNzA5Yjk1ODYyNGQ5MzkwNzkyMTc5MWM4YjBhMjU3ZTgzNDExMTJhMzVhNThiYWM1OGJhMDFiYTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.gZeYuBjTmOUDQOR_8IMuFtki-omuqUXUV6t5de9TKC0)
@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
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.
@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 forjsonProtocol
. 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!!