You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
Is there a .toJSON() function on mounted resources, to get plain JSON back or do we simply use js to convert the custom prototypes returned from mounted resources by doing something like JSON.parse(JSON.stringify(transactions))? I'm not seeing functionality to get plain JSON in mounted resources doc.
Shopify shows examples of mounted resources for nodejs and return types examples are plain JSON, but custom prototypes are returned. My hope is that my devs will be able to refer to nodejs examples on Shopify API Rest examples, which are showing mounted resources being used and be able to rely on the Shopify example responses to craft functionality in our app.
The issue is that custom prototypes returned from mounted resources (for my use case), cannot be saved in Cloud Firestore. E.g. this mounted resource call to get all transactions returns a custom prototype "Transaction"...
... which generates the following firestore error:
Error: Value for argument "data" is not a valid Firestore document. Couldn't serialize object of type "Transaction" (found in field "transaction_data.`0`"). Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator).
Custom prototypes are returned rather than plain JSON.
Steps to reproduce the problem
Use the Transaction mounted resource to get all transactions on an order and try to store in Cloud Firestore.
The text was updated successfully, but these errors were encountered:
Zelfapp
changed the title
Converting mounted REST resources from custom prototypes to standard objects
Need to get plain JSON from mounted REST resources rather than custom prototypes
Feb 3, 2023
👋🏻 @Zelfapp Sorry for the delay in responding (I thought I had already, my mistake).
As part of a fix for another issue, we added a toJSON() to the base class of the mounted resources in PR #690, and this was released as part of 6.2.0 on February 15 ... have you tried it with the latest release of the library?
Is there a
.toJSON()
function on mounted resources, to get plain JSON back or do we simply use js to convert the custom prototypes returned from mounted resources by doing something likeJSON.parse(JSON.stringify(transactions))
? I'm not seeing functionality to get plain JSON in mounted resources doc.Shopify shows examples of mounted resources for nodejs and return types examples are plain JSON, but custom prototypes are returned. My hope is that my devs will be able to refer to nodejs examples on Shopify API Rest examples, which are showing mounted resources being used and be able to rely on the Shopify example responses to craft functionality in our app.
The issue is that custom prototypes returned from mounted resources (for my use case), cannot be saved in Cloud Firestore. E.g. this mounted resource call to get all transactions returns a custom prototype "Transaction"...
... which generates the following firestore error:
@shopify/shopify-api
version: 6.1.0Expected behavior
Have the option to get plain JSON back as the examples responses on Shopify describe from mounted resources.
Actual behavior
Custom prototypes are returned rather than plain JSON.
Steps to reproduce the problem
The text was updated successfully, but these errors were encountered: