guillaumebriday / json-api-response-converter

Normalize your JSON:API response
https://json-api-response-converter.netlify.app/
MIT License
22 stars 1 forks source link

json-api-response-converter throwing RangeError: Maximum call stack size exceeded #5

Open flyingboy007 opened 4 years ago

flyingboy007 commented 4 years ago

Below is the response I receive from backend(using fastjsonapi serializer)

{
  "data": {
    "id": "12",
    "type": "seller_vertical",
    "attributes": {
      "aasm_state": "created",
      "created_at": "2020-04-16T10:06:56.041Z",
      "updated_at": "2020-04-16T10:06:56.041Z"
    },
    "relationships": {
      "documents": {
        "data": [
          {
            "id": "62",
            "type": "document"
          }
        ]
      }
    }
  },
  "included": [
    {
      "id": "62",
      "type": "document",
      "attributes": {
        "name": "test file",
        "status": "unverified",
        "approval_status": {
          "has_review_pending_data": true,
          "review_pending_data": {
            "id": 62,
            "is_delete": false,
            "document_notes": [],
            "document_status": "pending_verification"
          }
        }
      },
      "relationships": {
        "attachments": {
          "data": [
            {
              "id": "18",
              "type": "attachment"
            },
            {
              "id": "19",
              "type": "attachment"
            }
          ]
        }
      }
    },
    {
      "id": "18",
      "type": "attachment",
      "attributes": {
        "image_url": "some_url",
        "expiry_date": null,
        "status": "pending"
      },
      "relationships": {
        "document": {
          "data": {
            "id": "62",
            "type": "document"
          }
        }
      }
    },
    {
      "id": "19",
      "type": "attachment",
      "attributes": {
        "image_url": "some_url",
        "file_name": "unnamed.jpg",
        "expiry_date": null,
        "status": "pending"
      },
      "relationships": {
        "document": {
          "data": {
            "id": "62",
            "type": "document"
          }
        }
      }
    }
  ]
}

Here the seller_vertical object has_many documents. Similarly each document has_many attachments. But when I do
const formattedData = new JsonApiResponseConverter(data).formattedResponse

I am getting error

Exception: RangeError: Maximum call stack size exceeded at eval (webpack-internal

I created a sandbox with the error working sample