Skip to content

ErrorMaximum call stack size exceeded if included has cross references #106

Closed
@max-konin

Description

@max-konin

JSON:API payload

{
  "data": {
    "type": "article",
    "id": "1",
    "attributes": {
      "title": "title"
    },
    "relationships": {
      "author": { "data": { "type": "user", "id":  "1" } }
    }
  },
  "included": [
    {
      "type": "user",
      "id": "1",
      "attributes": {
        "email": "user@example.com"
      },
      "relationships": {
        "profile": { "data": { "type": "profile", "id":  "1" } }
      }
    },
    {
      "type": "profile",
      "id": "1",
      "attributes": {
        "firstName": "first-name",
        "lastName": "last-name"
      },
      "relationships": {
        "user": { "data": { "type": "user", "id":  "1" } }
      }
    }
  ]
}

Serializers

Serializer.register('article', {
  relationships: {
    author: { type: 'user' },
  },
});

Serializer.register('user', {
  relationships: {
    profile: { type: 'profile' },
  },
});

Serializer.register('profile', {
  relationships: {
    user: { type: 'user' },
  },
});

Expected result

{
  id: '1'.
  title: 'title',
  author: {
    id: '1'.
    email: 'user@example.com',
    profile: {
      id: '1'.
      firstName: 'first-name',
    }
  }
}

or

{
  id: '1'.
  title: 'title',
  author: {
    id: '1'.
    email: 'user@example.com',
    profile: {
      id: '1'.
      firstName: 'first-name',
      user: '1'
    }
  }
}

Actual ErrorMaximum call stack size exceeded

It may be useful to have beforeDeserialize hook or ignoreIncluded relationship option

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions