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

Converting regular attributes from 'undefined' to 'null' #202

Merged
merged 3 commits into from
Nov 21, 2019

Conversation

rduarte-as
Copy link
Contributor

@rduarte-as rduarte-as commented Nov 14, 2019

Serializer is sending undefined in the graphql payload, which gets converted to "undefined" in the backend
This change should default to null when undefined is present

@rduarte-as rduarte-as marked this pull request as ready for review November 14, 2019 21:02
Copy link

@earaujoassis earaujoassis left a comment

Choose a reason for hiding this comment

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

Whoa!

@rduarte-as rduarte-as changed the title Rdu/undefined to null Converting regular attributes from 'undefined' to 'null' Nov 14, 2019
@@ -44,7 +44,7 @@ export default DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, {
payloadKey = this.keyForAttribute(key);
}

json[payloadKey] = value;
json[payloadKey] = typeof value !== 'undefined' ? value : null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way to check for 'undefined' values?

@ars-dev-br
Copy link
Contributor

ars-dev-br commented Nov 19, 2019

I wonder if we should use the attribute's defaultValue instead of always defaulting to null. Say, if we have something like numOfThings: DS.attr('number', { defaultValue: 0 }), we may want to send 0 instead of undefined or null.

PS: Stopping to think about it, that's probably what EmberData is already doing. If it gets undefined, it looks for the defaultValue. In case the defaultValue is not set, it is also undefined. That's why setting the defaultValue to null in this PR worked

@rduarte-as rduarte-as merged commit e871266 into master Nov 21, 2019
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.

None yet

4 participants