Skip to content

Commit

Permalink
Merge pull request #202 from alphasights/rdu/undefined-to-null
Browse files Browse the repository at this point in the history
Converting regular attributes from 'undefined' to 'null'
  • Loading branch information
rduarte-as authored Nov 21, 2019
2 parents 651c6b8 + b08ac43 commit e871266
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion addon/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-graphql-adapter",
"version": "1.1.3",
"version": "1.1.4",
"description": "An Ember CLI adapter for GraphQL",
"keywords": [
"ember-addon"
Expand Down
32 changes: 31 additions & 1 deletion tests/integration/serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import DS from 'ember-data';
import { module, test } from 'qunit';

let env, store;
let Address, Blog, Profile, Post, User;
let Address, Blog, Profile, Post, User, NullUndefined;

module("integration/serializer - GraphQL serializer", {
beforeEach() {
Expand All @@ -31,10 +31,16 @@ module("integration/serializer - GraphQL serializer", {
profile: DS.belongsTo('profile', { async: false })
});

NullUndefined = DS.Model.extend({
undefinedStringField: DS.attr('string'),
nullStringField: DS.attr('string'),
});

env = setupStore({
adapter: '-graphql',
address: Address,
blog: Blog,
nullUndefined: NullUndefined,
post: Post,
profile: Profile,
user: User
Expand Down Expand Up @@ -367,6 +373,30 @@ test('serialize - simple', function(assert) {
});
});

test('serialize - extra simple null undefined cases', function(assert) {
assert.expect(1);

run(function() {
store.push({
data: {
type: 'null-undefined',
id: '1',
attributes: { nullStringField: null, undefinedStringField: undefined },
}
});
});

let expected = {
'nullStringField': null,
'undefinedStringField': null
};

run(function() {
let entity = store.peekRecord('null-undefined', 1);
assert.deepEqual(entity.serialize(), expected);
});
});

test('serialize - complex', function(assert) {
assert.expect(1);

Expand Down

0 comments on commit e871266

Please sign in to comment.