Skip to content

Ignore included resources without that don't have a corresponding ember-data model - #5178

Merged
bmac merged 1 commit into
warp-drive-data:masterfrom
lukemelia:ignore-unknown-jsonapi-resource-types
Sep 28, 2017
Merged

Ignore included resources without that don't have a corresponding ember-data model#5178
bmac merged 1 commit into
warp-drive-data:masterfrom
lukemelia:ignore-unknown-jsonapi-resource-types

Conversation

@lukemelia

@lukemelia lukemelia commented Sep 15, 2017

Copy link
Copy Markdown
Contributor

When the JSON API serializer encounters a resource with a type that doesn't resolve
to one of the application's Ember Data models, it replaces the object with null and
emits a warning. Prior to this commit, if that null was one of the sideloaded
(i.e. included) resources, the store would throw trying to ask for the null's type.
This commit makes the serializer drop any nulls out of the list of included resources
to avoid this problem.

To summarize, if your API attempts to include resources that you don't have models for,
a warning will be emitted and they will be ignored.

Fixes #4568

@lukemelia
lukemelia force-pushed the ignore-unknown-jsonapi-resource-types branch from bcc542d to de744e0 Compare September 16, 2017 00:24
Comment thread addon/serializers/json-api.js Outdated
ret[i] = normalized;
}
if (needsCompacting) {
ret = ret.filter(Boolean);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just use push and an explicit check for not null vs preallocating length here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good @runspired. I was concerned about changing the performance characteristics of the happy path, but I agree that is clearer. I'll make the change now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…responding ember-data model

When the JSON API serializer encounters a resource with a type that doesn't resolve
to one of the application's Ember Data models, it replaces the object with `null` and
emits a warning. Prior to this commit, if that `null` was one of the sideloaded
(i.e. `included`) resources, the store would throw trying to get the `null`'s type.
This commit makes the serializer drops any nulls out of the list of included resources
to avoid this problem.

To summarize, if your API attempts to include resources that you don't have models for,
a warning will be emitted and they will be ignored.

Fixes warp-drive-data#4568
@lukemelia
lukemelia force-pushed the ignore-unknown-jsonapi-resource-types branch from de744e0 to 056a1c9 Compare September 16, 2017 21:01

@runspired runspired left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1

@bmac
bmac merged commit 16e1670 into warp-drive-data:master Sep 28, 2017
@bmac

bmac commented Sep 28, 2017

Copy link
Copy Markdown
Contributor

Thanks @lukemelia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read property 'type' of null

3 participants