From 47abfbb424d148d3164fd1b801764897bd96fa0e Mon Sep 17 00:00:00 2001 From: Boris Nieuwenhuis Date: Tue, 2 May 2017 19:56:52 +0200 Subject: [PATCH] replace object.assign by util.assign to make it work in IE check if source is set update CHANGELOG.md with fix description --- CHANGELOG.md | 1 + src/core/QueryManager.ts | 7 ++++--- src/queries/getFromAST.ts | 4 +++- src/util/assign.ts | 12 +++++++++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5993e0e9015..100f3790b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### vNEXT - Feature+Fix: Introduce "standby" fetchPolicy to mark queries that are not currently active, but should be available for refetchQueries and updateQueries [PR #1636](https://github.com/apollographql/apollo-client/pull/1636) - Feature: Print a warning when heuristically matching fragments on interface/union [PR #1635](https://github.com/apollographql/apollo-client/pull/1635) +- Fix: Replace usage of Object.assign with util.assign to make it work in IE, make util.assign work with undefined and null sources as Object.assign does [PR #1643](https://github.com/apollographql/apollo-client/pull/1643) ### 1.1.1 - Fix: Remove ability to set default fetchPolicy, which broke polling queries [PR #1630](https://github.com/apollographql/apollo-client/pull/1630) diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 6f4e5c9027a..3095ee7f692 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -9,6 +9,7 @@ import { } from '../transport/Deduplicator'; import { isEqual } from '../util/isEqual'; +import { assign } from '../util/assign'; import { QueryListener, @@ -258,7 +259,7 @@ export class QueryManager { mutation = addTypenameToDocument(mutation); } - variables = Object.assign(getDefaultValues(getMutationDefinition(mutation)), variables); + variables = assign({}, getDefaultValues(getMutationDefinition(mutation)), variables); const mutationString = print(mutation); const request = { @@ -647,7 +648,7 @@ export class QueryManager { if (queryDefinition.variableDefinitions && queryDefinition.variableDefinitions.length) { const defaultValues = getDefaultValues(queryDefinition); - options.variables = Object.assign(defaultValues, options.variables); + options.variables = assign({}, defaultValues, options.variables); } if (typeof options.notifyOnNetworkStatusChange === 'undefined') { @@ -844,7 +845,7 @@ export class QueryManager { transformedDoc = addTypenameToDocument(transformedDoc); } - const variables = Object.assign(getDefaultValues(getOperationDefinition(query)), options.variables); + const variables = assign({}, getDefaultValues(getOperationDefinition(query)), options.variables); const request: Request = { query: transformedDoc, diff --git a/src/queries/getFromAST.ts b/src/queries/getFromAST.ts index f706601517e..872ca8ce5af 100644 --- a/src/queries/getFromAST.ts +++ b/src/queries/getFromAST.ts @@ -10,6 +10,8 @@ import { valueToObjectRepresentation, } from '../data/storeUtils'; +import { assign } from '../util/assign'; + export function getMutationDefinition(doc: DocumentNode): OperationDefinitionNode { checkDocument(doc); @@ -250,7 +252,7 @@ export function getDefaultValues(definition: OperationDefinitionNode): { [key: s return defaultValueObj; }); - return Object.assign({}, ...defaultValues); + return assign({}, ...defaultValues); } return {}; diff --git a/src/util/assign.ts b/src/util/assign.ts index 1dcd1349cc9..80523da16b0 100644 --- a/src/util/assign.ts +++ b/src/util/assign.ts @@ -13,8 +13,14 @@ export function assign ( target: { [key: string]: any }, ...sources: Array<{ [key: string]: any }>, ): { [key: string]: any } { - sources.forEach(source => Object.keys(source).forEach(key => { - target[key] = source[key]; - })); + sources.forEach(source => { + + if (typeof(source) === 'undefined' || source === null) { + return; + } + Object.keys(source).forEach(key => { + target[key] = source[key]; + }); + }); return target; }