From db7b0fa5100bd43561cb861d86938278dcac8330 Mon Sep 17 00:00:00 2001 From: Jon Sweet Date: Sat, 16 Jun 2018 15:50:55 -0600 Subject: [PATCH 1/4] Add test for filtering array of data --- .../src/__tests__/utilities.ts | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/packages/graphql-anywhere/src/__tests__/utilities.ts b/packages/graphql-anywhere/src/__tests__/utilities.ts index cf446b8c70c..2f6f9e6bff6 100644 --- a/packages/graphql-anywhere/src/__tests__/utilities.ts +++ b/packages/graphql-anywhere/src/__tests__/utilities.ts @@ -33,11 +33,53 @@ describe('utilities', () => { square: 'abc', }, }; + const arrayData = [ + { + alias: 'Bob', + name: 'Wrong', + height: 1.89, + avatar: { + square: 'abc', + circle: 'def', + triangle: 'qwe', + }, + }, + { + alias: 'Tom', + name: 'Right', + height: 1.77, + avatar: { + square: 'jkl', + circle: 'bnm', + triangle: 'uio', + }, + }, + ]; + const filteredArrayData = [ + { + alias: 'Bob', + height: 1.89, + avatar: { + square: 'abc', + }, + }, + { + alias: 'Tom', + height: 1.77, + avatar: { + square: 'jkl', + }, + }, + ]; it('can filter data', () => { expect(filter(doc, data)).toEqual(filteredData); }); + it('can filter an array of data', () => { + expect(filter(doc, arrayData)).toEqual(filteredArrayData); + }); + it('can check matching data', () => { check(doc, filteredData); }); @@ -90,11 +132,53 @@ describe('utilities', () => { square: 'abc', }, }; + const arrayData = [ + { + alias: 'Bob', + name: 'Wrong', + height: 1.89, + avatar: { + square: 'abc', + circle: 'def', + triangle: 'qwe', + }, + }, + { + alias: 'Tom', + name: 'Right', + height: 1.77, + avatar: { + square: 'jkl', + circle: 'bnm', + triangle: 'uio', + }, + }, + ]; + const filteredArrayData = [ + { + alias: 'Bob', + height: 1.89, + avatar: { + square: 'abc', + }, + }, + { + alias: 'Tom', + height: 1.77, + avatar: { + square: 'jkl', + }, + }, + ]; it('can filter data', () => { expect(filter(doc, data)).toEqual(filteredData); }); + it('can filter an array of data', () => { + expect(filter(doc, arrayData)).toEqual(filteredArrayData); + }); + it('can check matching data', () => { check(doc, filteredData); }); @@ -147,11 +231,53 @@ describe('utilities', () => { square: 'abc', }, }; + const arrayData = [ + { + alias: 'Bob', + name: 'Wrong', + height: 1.89, + avatar: { + square: 'abc', + circle: 'def', + triangle: 'qwe', + }, + }, + { + alias: 'Tom', + name: 'Right', + height: 1.77, + avatar: { + square: 'jkl', + circle: 'bnm', + triangle: 'uio', + }, + }, + ]; + const filteredArrayData = [ + { + alias: 'Bob', + height: 1.89, + avatar: { + square: 'abc', + }, + }, + { + alias: 'Tom', + height: 1.77, + avatar: { + square: 'jkl', + }, + }, + ]; it('can filter data', () => { expect(filter(doc, data)).toEqual(filteredData); }); + it('can filter an array of data', () => { + expect(filter(doc, arrayData)).toEqual(filteredArrayData); + }); + it('can check matching data', () => { check(doc, filteredData); }); @@ -208,11 +334,55 @@ describe('utilities', () => { circle: 'def', }, }; + const arrayData = [ + { + alias: 'Bob', + name: 'Wrong', + height: 1.89, + avatar: { + square: 'abc', + circle: 'def', + triangle: 'qwe', + }, + }, + { + alias: 'Tom', + name: 'Right', + height: 1.77, + avatar: { + square: 'jkl', + circle: 'bnm', + triangle: 'uio', + }, + }, + ]; + const filteredArrayData = [ + { + alias: 'Bob', + height: 1.89, + avatar: { + square: 'abc', + circle: 'def', + }, + }, + { + alias: 'Tom', + height: 1.77, + avatar: { + square: 'jkl', + circle: 'bnm', + }, + }, + ]; it('can filter data', () => { expect(filter(doc, data)).toEqual(filteredData); }); + it('can filter an array of data', () => { + expect(filter(doc, arrayData)).toEqual(filteredArrayData); + }); + it('can check matching data', () => { check(doc, filteredData); }); @@ -229,6 +399,14 @@ describe('utilities', () => { }); }).toThrow(); + expect(() => { + check(doc, [ + { + name: 'Wrong', + }, + ]); + }).toThrow(); + expect(() => { check(doc, { alias: 'Bob', From 7aac9f9548e38c786ce23f3378e21b579087c23f Mon Sep 17 00:00:00 2001 From: Jon Sweet Date: Sat, 16 Jun 2018 15:51:55 -0600 Subject: [PATCH 2/4] Add check for array of data Return a mapping of data objects to an array of filtered data objects --- packages/graphql-anywhere/src/utilities.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/graphql-anywhere/src/utilities.ts b/packages/graphql-anywhere/src/utilities.ts index cf48289b81a..1ae11424752 100644 --- a/packages/graphql-anywhere/src/utilities.ts +++ b/packages/graphql-anywhere/src/utilities.ts @@ -13,7 +13,9 @@ export function filter(doc: DocumentNode, data: any): any { return root[info.resultKey]; }; - return graphql(resolver, doc, data); + return Array.isArray(data) + ? data.map(dataObj => graphql(resolver, doc, dataObj)) + : graphql(resolver, doc, data); } // TODO: we should probably make check call propType and then throw, From ec657bd68ce432fbadd65460c3533826905b206f Mon Sep 17 00:00:00 2001 From: Jonathan Sweet <31966868+JSweet314@users.noreply.github.com> Date: Sat, 16 Jun 2018 17:27:51 -0600 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 241 ++++++++++++++++++++++++++------------------------- 1 file changed, 123 insertions(+), 118 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a9bc313c56..11c1fde915a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,66 +1,66 @@ -**Note:** This is a cumulative changelog that outlines all of the Apollo Client project child package changes that were bundled into a specific `apollo-client` release. - -### 2.3.4 (June 13, 2018) - -### Apollo Client (2.3.4) - -- Export the `QueryOptions` interface, to make sure it can be used by other - projects (like `apollo-angular`). -- Fixed an issue caused by typescript changes to the constructor - `defaultOptions` param, that prevented `query` defaults from passing type - checks. - ([@hwillson](https://github.com/hwillson) in [#3585](https://github.com/apollographql/apollo-client/pull/3585)) - -### Apollo Boost (0.1.9) - -- No changes - -### Apollo Cache (1.1.11) - -- No changes - -### Apollo Cache In-Memory (1.2.4) - -- No changes - -### Apollo Utilities (1.0.15) - -- No changes - -### Apollo GraphQL Anywhere (4.1.13) - -- No changes - - -## 2.3.3 (June 13, 2018) - -### Apollo Client (2.3.3) - -- Typescript improvements. Made observable query parameterized on data and - variables: `ObservableQuery` - ([@excitement-engineer](https://github.com/excitement-engineer) in [#3140](https://github.com/apollographql/apollo-client/pull/3140)) -- Added optional generics to cache manipulation methods (typescript). - ([@mvestergaard](https://github.com/mvestergaard) in [#3541](https://github.com/apollographql/apollo-client/pull/3541)) -- Typescript improvements. Created a new `QueryOptions` interface that - is now used by `ApolloClient.query` options, instead of the previous - `WatchQueryOptions` interface. This helps reduce confusion (especially - in the docs) that made it look like `ApolloClient.query` accepted - `ApolloClient.watchQuery` only options, like `pollingInterval`. - ([@hwillson](https://github.com/hwillson) in [#3569](https://github.com/apollographql/apollo-client/pull/3569)) - -### Apollo Boost (0.1.8) - +**Note:** This is a cumulative changelog that outlines all of the Apollo Client project child package changes that were bundled into a specific `apollo-client` release. + +### 2.3.4 (June 13, 2018) + +### Apollo Client (2.3.4) + +- Export the `QueryOptions` interface, to make sure it can be used by other + projects (like `apollo-angular`). +- Fixed an issue caused by typescript changes to the constructor + `defaultOptions` param, that prevented `query` defaults from passing type + checks. + ([@hwillson](https://github.com/hwillson) in [#3585](https://github.com/apollographql/apollo-client/pull/3585)) + +### Apollo Boost (0.1.9) + +- No changes + +### Apollo Cache (1.1.11) + +- No changes + +### Apollo Cache In-Memory (1.2.4) + +- No changes + +### Apollo Utilities (1.0.15) + +- No changes + +### Apollo GraphQL Anywhere (4.1.13) + +- No changes + + +## 2.3.3 (June 13, 2018) + +### Apollo Client (2.3.3) + +- Typescript improvements. Made observable query parameterized on data and + variables: `ObservableQuery` + ([@excitement-engineer](https://github.com/excitement-engineer) in [#3140](https://github.com/apollographql/apollo-client/pull/3140)) +- Added optional generics to cache manipulation methods (typescript). + ([@mvestergaard](https://github.com/mvestergaard) in [#3541](https://github.com/apollographql/apollo-client/pull/3541)) +- Typescript improvements. Created a new `QueryOptions` interface that + is now used by `ApolloClient.query` options, instead of the previous + `WatchQueryOptions` interface. This helps reduce confusion (especially + in the docs) that made it look like `ApolloClient.query` accepted + `ApolloClient.watchQuery` only options, like `pollingInterval`. + ([@hwillson](https://github.com/hwillson) in [#3569](https://github.com/apollographql/apollo-client/pull/3569)) + +### Apollo Boost (0.1.8) + - Allow `cache` to be given as a configuration option to `ApolloBoost`. ([@dandean](https://github.com/dandean) in [#3561](https://github.com/apollographql/apollo-client/pull/3561)) - Allow `headers` and `credentials` to be passed in as configuration parameters to the `apollo-boost` `ApolloClient` constructor. ([@rzane](https://github.com/rzane) in [#3098](https://github.com/apollographql/apollo-client/pull/3098)) - -### Apollo Cache (1.1.10) - -- Added optional generics to cache manipulation methods (typescript). + +### Apollo Cache (1.1.10) + +- Added optional generics to cache manipulation methods (typescript). ([@mvestergaard](https://github.com/mvestergaard) in [#3541](https://github.com/apollographql/apollo-client/pull/3541)) - + ### Apollo Cache In-Memory (1.2.3) - Added optional generics to cache manipulation methods (typescript). @@ -68,70 +68,75 @@ - Restore non-enumerability of `resultFields[ID_KEY]`. ([@benjamn](https://github.com/benjamn) in [#3544](https://github.com/apollographql/apollo-client/pull/3544)) - Cache query documents transformed by InMemoryCache. - ([@benjamn](https://github.com/benjamn) in [#3553](https://github.com/apollographql/apollo-client/pull/3553)) - -### Apollo Utilities (1.0.14) - -- Store key names generated by `getStoreKeyName` now leverage a more - deterministic approach to handling JSON based strings. This prevents store - key names from differing when using `args` like - `{ prop1: 'value1', prop2: 'value2' }` and - `{ prop2: 'value2', prop1: 'value1' }`. - ([@gdi2290](https://github.com/gdi2290) in [#2869](https://github.com/apollographql/apollo-client/pull/2869)) -- Avoid needless `hasOwnProperty` check in `deepFreeze`. - ([@benjamn](https://github.com/benjamn) in [#3545](https://github.com/apollographql/apollo-client/pull/3545)) - -### Apollo GraphQL Anywhere (4.1.12) - -- No new changes. - - -## 2.3.2 (May 29, 2018) - -### Apollo Client (2.3.2) - -- Fix SSR and `cache-and-network` fetch policy - ([@dastoori](https://github.com/dastoori) in [#3372](https://github.com/apollographql/apollo-client/pull/3372)) -- Fixed an issue where the `updateQuery` method passed to - `ObservableQuery.fetchMore` was receiving the original query variables, - instead of the new variables that it used to fetch more data. - ([@abhiaiyer91](https://github.com/abhiaiyer91) in [#3500](https://github.com/apollographql/apollo-client/pull/3500)) -- Fixed an issue involving `Object.setPrototypeOf()` not working on JSC - (Android), by instead setting the `prototype` of `this` manually. - ([@seklyza](https://github.com/seklyza) in [#3306](https://github.com/apollographql/apollo-client/pull/3306)) -- Added safeguards to make sure `QueryStore.initQuery` and - `QueryStore.markQueryResult` don't try to set the network status of a - `fetchMoreForQueryId` query, if it does not exist in the store. This was - happening when a query component was unmounted while a `fetchMore` was still - in flight. - ([@conrad-vanl](https://github.com/conrad-vanl) in [#3367](https://github.com/apollographql/apollo-client/pull/3367), [@doomsower](https://github.com/doomsower) in [#3469](https://github.com/apollographql/apollo-client/pull/3469)) - -### Apollo Boost (0.1.7) - -- Various internal code cleanup, tooling and dependency changes. - -### Apollo Cache (1.1.9) - -- Various internal code cleanup, tooling and dependency changes. - + ([@benjamn](https://github.com/benjamn) in [#3553](https://github.com/apollographql/apollo-client/pull/3553)) + +### Apollo Utilities (1.0.14) + +- Store key names generated by `getStoreKeyName` now leverage a more + deterministic approach to handling JSON based strings. This prevents store + key names from differing when using `args` like + `{ prop1: 'value1', prop2: 'value2' }` and + `{ prop2: 'value2', prop1: 'value1' }`. + ([@gdi2290](https://github.com/gdi2290) in [#2869](https://github.com/apollographql/apollo-client/pull/2869)) +- Avoid needless `hasOwnProperty` check in `deepFreeze`. + ([@benjamn](https://github.com/benjamn) in [#3545](https://github.com/apollographql/apollo-client/pull/3545)) + +### Apollo GraphQL Anywhere (4.1.12) + +- No new changes. + + +## 2.3.2 (May 29, 2018) + +### Apollo Client (2.3.2) + +- Fix SSR and `cache-and-network` fetch policy + ([@dastoori](https://github.com/dastoori) in [#3372](https://github.com/apollographql/apollo-client/pull/3372)) +- Fixed an issue where the `updateQuery` method passed to + `ObservableQuery.fetchMore` was receiving the original query variables, + instead of the new variables that it used to fetch more data. + ([@abhiaiyer91](https://github.com/abhiaiyer91) in [#3500](https://github.com/apollographql/apollo-client/pull/3500)) +- Fixed an issue involving `Object.setPrototypeOf()` not working on JSC + (Android), by instead setting the `prototype` of `this` manually. + ([@seklyza](https://github.com/seklyza) in [#3306](https://github.com/apollographql/apollo-client/pull/3306)) +- Added safeguards to make sure `QueryStore.initQuery` and + `QueryStore.markQueryResult` don't try to set the network status of a + `fetchMoreForQueryId` query, if it does not exist in the store. This was + happening when a query component was unmounted while a `fetchMore` was still + in flight. + ([@conrad-vanl](https://github.com/conrad-vanl) in [#3367](https://github.com/apollographql/apollo-client/pull/3367), [@doomsower](https://github.com/doomsower) in [#3469](https://github.com/apollographql/apollo-client/pull/3469)) + +### Apollo Boost (0.1.7) + +- Various internal code cleanup, tooling and dependency changes. + +### Apollo Cache (1.1.9) + +- Various internal code cleanup, tooling and dependency changes. + ### Apollo Cache In-Memory (1.2.2) - Fixed an issue that caused fragment only queries to sometimes fail. ([@abhiaiyer91](https://github.com/abhiaiyer91) in [#3507](https://github.com/apollographql/apollo-client/pull/3507)) - Fixed cache invalidation for inlined mixed types in union fields within arrays. - ([@dferber90](https://github.com/dferber90) in [#3422](https://github.com/apollographql/apollo-client/pull/3422)) - -### Apollo Utilities (1.0.13) - -- Make `maybeDeepFreeze` a little more defensive, by always using - `Object.prototype.hasOwnProperty` (to avoid cases where the object being - frozen doesn't have its own `hasOwnProperty`). - ([@jorisroling](https://github.com/jorisroling) in [#3418](https://github.com/apollographql/apollo-client/pull/3418)) -- Remove certain small internal caches to prevent memory leaks when using SSR. - ([@brunorzn](https://github.com/brunorzn) in [#3444](https://github.com/apollographql/apollo-client/pull/3444)) - -### Apollo GraphQL Anywhere (4.1.11) - -- Source files are now excluded when publishing to npm. - ([@hwillson](https://github.com/hwillson) in [#3454](https://github.com/apollographql/apollo-client/pull/3454)) + ([@dferber90](https://github.com/dferber90) in [#3422](https://github.com/apollographql/apollo-client/pull/3422)) + +### Apollo Utilities (1.0.13) + +- Make `maybeDeepFreeze` a little more defensive, by always using + `Object.prototype.hasOwnProperty` (to avoid cases where the object being + frozen doesn't have its own `hasOwnProperty`). + ([@jorisroling](https://github.com/jorisroling) in [#3418](https://github.com/apollographql/apollo-client/pull/3418)) +- Remove certain small internal caches to prevent memory leaks when using SSR. + ([@brunorzn](https://github.com/brunorzn) in [#3444](https://github.com/apollographql/apollo-client/pull/3444)) + +### Apollo GraphQL Anywhere (4.1.11) + +- Source files are now excluded when publishing to npm. + ([@hwillson](https://github.com/hwillson) in [#3454](https://github.com/apollographql/apollo-client/pull/3454)) + +### Apollo GraphQL Anywhere (4.1.13) + +- Add support for arrays to graphql-anywheres filter utility. + ([@jsweet314](https://github.com/jsweet314) in [#3591](https://github.com/apollographql/apollo-client/pull/3591)) From b07c4d8d64a64c1cdd9dc7e143ba51bb7eca7a25 Mon Sep 17 00:00:00 2001 From: Hugh Willson Date: Tue, 10 Jul 2018 11:07:22 -0700 Subject: [PATCH 4/4] Changelog updates --- packages/graphql-anywhere/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/graphql-anywhere/CHANGELOG.md b/packages/graphql-anywhere/CHANGELOG.md index a5e6a68cf12..3b7837936f1 100644 --- a/packages/graphql-anywhere/CHANGELOG.md +++ b/packages/graphql-anywhere/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +### vNext + +- Add support for arrays to `filter`. + [PR #3591](https://github.com/apollographql/apollo-client/pull/3591) + ### 4.1.14 - No changes.