From bd46b7fc283a0de2d93d548a2495b17be5c0fe7e Mon Sep 17 00:00:00 2001 From: chris-hamper Date: Fri, 17 Mar 2017 14:18:04 -0400 Subject: [PATCH 1/7] Account for recent changes to JSON API Drupal module Change API namespace from "api" to "jsonapi", don't add "_format=api_json" query parameter any more --- addon/adapter.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addon/adapter.js b/addon/adapter.js index 7c45644..df31fc1 100644 --- a/addon/adapter.js +++ b/addon/adapter.js @@ -7,7 +7,7 @@ const { } = Ember; export default DS.JSONAPIAdapter.extend({ - namespace: 'api', + namespace: 'jsonapi', drupalMapper: service(), pathForType(modelName) { @@ -40,7 +40,6 @@ export default DS.JSONAPIAdapter.extend({ query = this.sortQueryParams(drupalQuery); } - query._format = 'api_json'; return this.ajax(url, 'GET', { data: query }); }, -}); \ No newline at end of file +}); From 7fc97e57a09ccf6486a35c0076de9f449de95ace Mon Sep 17 00:00:00 2001 From: chris-hamper Date: Mon, 27 Mar 2017 12:36:30 -0400 Subject: [PATCH 2/7] buildQuery() override no longer needed to add _format query param --- addon/adapter.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/addon/adapter.js b/addon/adapter.js index df31fc1..3f0e4d4 100644 --- a/addon/adapter.js +++ b/addon/adapter.js @@ -17,12 +17,6 @@ export default DS.JSONAPIAdapter.extend({ return entity + '/' + bundle; }, - buildQuery(snapshot) { - let query = this._super(...arguments); - query._format = 'api_json'; - return query; - }, - query(store, type, query) { let drupalQuery = { filter: {} }, queryFields = Object.keys(query), From ca7f0aa96221d791fe3864c40555e55efd10d1d7 Mon Sep 17 00:00:00 2001 From: Chris Hamper Date: Mon, 10 Apr 2017 16:29:48 -0400 Subject: [PATCH 3/7] Fix findMany() to work with JSON API beta1 Fixes option to coallesce find requests --- addon/adapter.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/addon/adapter.js b/addon/adapter.js index 3f0e4d4..8af877e 100644 --- a/addon/adapter.js +++ b/addon/adapter.js @@ -36,4 +36,18 @@ export default DS.JSONAPIAdapter.extend({ return this.ajax(url, 'GET', { data: query }); }, + + findMany(store, type, ids, snapshots) { + const url = this.buildURL(type.modelName, ids, snapshots, 'findMany'); + const filter = { + c: { + condition: { + path: 'uuid', + operator: 'IN', + value: ids + } + } + }; + return this.ajax(url, 'GET', { data: { filter: filter } }); + }, }); From 442d0336457b7a3067a4a8976eab95573f123af5 Mon Sep 17 00:00:00 2001 From: Chris Hamper Date: Mon, 10 Apr 2017 16:33:04 -0400 Subject: [PATCH 4/7] Prevent dash-ification of relationship keys (JSON API types) --- addon/serializer.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addon/serializer.js b/addon/serializer.js index 822dfb6..82d7311 100644 --- a/addon/serializer.js +++ b/addon/serializer.js @@ -65,6 +65,11 @@ const DrupalJSONAPISerializer = JSONAPISerializer.extend({ } return relationships; }, + + keyForRelationship(key) { + // Prevent dash-ification of underscores in relationship keys + return key; + }, }); export default DrupalJSONAPISerializer; \ No newline at end of file From 4ab7947c773c55659d5def3c1e697142e84f921d Mon Sep 17 00:00:00 2001 From: Chris Hamper Date: Mon, 10 Apr 2017 16:33:54 -0400 Subject: [PATCH 5/7] (Workaround) Skip serialization of hasMany relationships with no members --- addon/serializer.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addon/serializer.js b/addon/serializer.js index 82d7311..ce57c9d 100644 --- a/addon/serializer.js +++ b/addon/serializer.js @@ -70,6 +70,17 @@ const DrupalJSONAPISerializer = JSONAPISerializer.extend({ // Prevent dash-ification of underscores in relationship keys return key; }, + + // @todo - remove when https://www.drupal.org/node/2868479 is committed + serializeHasMany(snapshot, json, relationship) { + // Only serialize hasMany relationships that actually contain items + let hasMany = snapshot.hasMany(relationship.key); + if (hasMany !== undefined) { + if (hasMany.length) { + this._super(...arguments); + } + } + }, }); export default DrupalJSONAPISerializer; \ No newline at end of file From 093513b75676810eef25ee0e9937cad49ea1f89d Mon Sep 17 00:00:00 2001 From: Chris Hamper Date: Mon, 10 Apr 2017 16:34:46 -0400 Subject: [PATCH 6/7] Fix missing newline --- addon/serializer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/serializer.js b/addon/serializer.js index ce57c9d..0ca6707 100644 --- a/addon/serializer.js +++ b/addon/serializer.js @@ -83,4 +83,4 @@ const DrupalJSONAPISerializer = JSONAPISerializer.extend({ }, }); -export default DrupalJSONAPISerializer; \ No newline at end of file +export default DrupalJSONAPISerializer; From 32617d3dc211a571bc6d194011393f3569bc27ae Mon Sep 17 00:00:00 2001 From: Chris Hamper Date: Mon, 10 Apr 2017 23:04:23 -0400 Subject: [PATCH 7/7] Revert "(Workaround) Skip serialization of hasMany relationships with no members" This reverts commit 4ab7947c773c55659d5def3c1e697142e84f921d. --- addon/serializer.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/addon/serializer.js b/addon/serializer.js index 0ca6707..08e5930 100644 --- a/addon/serializer.js +++ b/addon/serializer.js @@ -70,17 +70,6 @@ const DrupalJSONAPISerializer = JSONAPISerializer.extend({ // Prevent dash-ification of underscores in relationship keys return key; }, - - // @todo - remove when https://www.drupal.org/node/2868479 is committed - serializeHasMany(snapshot, json, relationship) { - // Only serialize hasMany relationships that actually contain items - let hasMany = snapshot.hasMany(relationship.key); - if (hasMany !== undefined) { - if (hasMany.length) { - this._super(...arguments); - } - } - }, }); export default DrupalJSONAPISerializer;