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

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

Closed
max-konin opened this issue Apr 26, 2020 · 0 comments · Fixed by #107
Closed

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

max-konin opened this issue Apr 26, 2020 · 0 comments · Fixed by #107
Assignees
Labels

Comments

@max-konin
Copy link
Contributor

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

@danivek danivek self-assigned this Apr 27, 2020
@danivek danivek added the bug label Apr 27, 2020
danivek added a commit that referenced this issue Apr 30, 2020
fix "Maximum call stack size exceeded" error.

closes #106
danivek added a commit that referenced this issue Apr 30, 2020
fix "Maximum call stack size exceeded" error.

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

Successfully merging a pull request may close this issue.

2 participants