From 8e83fdabe0d237bb0e93d7814a5eaee3989488d8 Mon Sep 17 00:00:00 2001 From: Dhaivat Pandya Date: Wed, 20 Jul 2016 15:30:22 -0700 Subject: [PATCH 1/3] added the fragment flattening and added modules to typings --- ambient.d.ts | 10 ++++++++++ package.json | 1 + src/index.ts | 7 ++++++- test/client.ts | 6 +++--- typings/browser/globals/apollo-client/index.d.ts | 10 ++++++++++ .../browser/globals/apollo-client/typings.json | 4 ++-- typings/browser/modules/lodash/index.d.ts | 8 ++++---- typings/main/globals/apollo-client/index.d.ts | 15 ++++++++++----- typings/main/globals/apollo-client/typings.json | 4 ++-- typings/main/modules/lodash/index.d.ts | 8 ++++---- 10 files changed, 52 insertions(+), 21 deletions(-) diff --git a/ambient.d.ts b/ambient.d.ts index e5b5d1ff8a1..47ef18ba9e5 100644 --- a/ambient.d.ts +++ b/ambient.d.ts @@ -93,6 +93,16 @@ declare module 'lodash.identity' { export = main.identity; } +declare module 'lodash.flatten' { + import main = require('~lodash/index'); + export = main.flatten; +} + +declare module 'lodash.pick' { + import main = require('~lodash/index'); + export = main.pick; +} + /* GRAPHQL diff --git a/package.json b/package.json index 02bd8e60f5f..2d965752453 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "lodash.assign": "^4.0.8", "lodash.clonedeep": "^4.3.2", "lodash.countby": "^4.4.0", + "lodash.flatten": "^4.2.0", "lodash.forown": "^4.1.0", "lodash.has": "^4.3.1", "lodash.identity": "^3.0.0", diff --git a/src/index.ts b/src/index.ts index fea35d70ace..577eaf90c67 100644 --- a/src/index.ts +++ b/src/index.ts @@ -75,6 +75,7 @@ import { import isUndefined = require('lodash.isundefined'); import assign = require('lodash.assign'); +import flatten = require('lodash.flatten'); // We expose the print method from GraphQL so that people that implement // custom network interfaces can turn query ASTs into query strings as needed. @@ -113,7 +114,11 @@ let printFragmentWarnings = true; // that the fragment in the document depends on. The fragment definition array from the document // is concatenated with the fragment definition array passed as the second argument and this // concatenated array is returned. -export function createFragment(doc: Document, fragments: FragmentDefinition[] = []): FragmentDefinition[] { +export function createFragment( + doc: Document, + fragments: (FragmentDefinition[] | FragmentDefinition[][]) = [] +): FragmentDefinition[] { + fragments = flatten(fragments) as FragmentDefinition[] ; const fragmentDefinitions = getFragmentDefinitions(doc); fragmentDefinitions.forEach((fragmentDefinition) => { const fragmentName = fragmentDefinition.name.value; diff --git a/test/client.ts b/test/client.ts index f32fee23ee3..cec63833005 100644 --- a/test/client.ts +++ b/test/client.ts @@ -1115,10 +1115,10 @@ describe('client', () => { personDetails }`; const fragments1 = createFragment(fragmentDoc1); - const fragments2 = createFragment(fragmentDoc2, fragments1); - const fragments3 = createFragment(fragmentDoc3, fragments2); + const fragments2 = createFragment(fragmentDoc2); + const fragments3 = createFragment(fragmentDoc3, [fragments1, fragments2]); assert.equal(fragments1.length, 1); - assert.equal(fragments2.length, 2); + assert.equal(fragments2.length, 1); assert.equal(fragments3.length, 3); }); diff --git a/typings/browser/globals/apollo-client/index.d.ts b/typings/browser/globals/apollo-client/index.d.ts index a3330da578b..398410c95fd 100644 --- a/typings/browser/globals/apollo-client/index.d.ts +++ b/typings/browser/globals/apollo-client/index.d.ts @@ -90,6 +90,16 @@ declare module 'lodash.identity' { export = main.identity; } +declare module 'lodash.flatten' { + import main = require('~lodash/index'); + export = main.flatten; +} + +declare module 'lodash.pick' { + import main = require('~lodash/index'); + export = main.pick; +} + /* GRAPHQL diff --git a/typings/browser/globals/apollo-client/typings.json b/typings/browser/globals/apollo-client/typings.json index 8ce81b417e3..4bf52138d91 100644 --- a/typings/browser/globals/apollo-client/typings.json +++ b/typings/browser/globals/apollo-client/typings.json @@ -1,8 +1,8 @@ { "resolution": "browser", "tree": { - "src": "/Users/sashko/git/apollo-client/ambient.d.ts", + "src": "/Users/dhaivatpandya/dev/apollo-client/ambient.d.ts", "raw": "file:./ambient.d.ts", - "typings": "/Users/sashko/git/apollo-client/ambient.d.ts" + "typings": "/Users/dhaivatpandya/dev/apollo-client/ambient.d.ts" } } diff --git a/typings/browser/modules/lodash/index.d.ts b/typings/browser/modules/lodash/index.d.ts index df22d03b322..bf8c7fc478c 100644 --- a/typings/browser/modules/lodash/index.d.ts +++ b/typings/browser/modules/lodash/index.d.ts @@ -18290,10 +18290,10 @@ export = _; interface Map {} } declare module 'lodash/index' { -import main = require('~lodash/index'); -export = main; +import alias = require('~lodash/index'); +export = alias; } declare module 'lodash' { -import main = require('~lodash/index'); -export = main; +import alias = require('~lodash/index'); +export = alias; } diff --git a/typings/main/globals/apollo-client/index.d.ts b/typings/main/globals/apollo-client/index.d.ts index cb9124f4f15..398410c95fd 100644 --- a/typings/main/globals/apollo-client/index.d.ts +++ b/typings/main/globals/apollo-client/index.d.ts @@ -40,11 +40,6 @@ declare module 'lodash.merge' { export = main.merge; } -declare module 'lodash.pick' { - import main = require('~lodash/index'); - export = main.pick; -} - declare module 'lodash.includes' { import main = require('~lodash/index'); export = main.includes; @@ -95,6 +90,16 @@ declare module 'lodash.identity' { export = main.identity; } +declare module 'lodash.flatten' { + import main = require('~lodash/index'); + export = main.flatten; +} + +declare module 'lodash.pick' { + import main = require('~lodash/index'); + export = main.pick; +} + /* GRAPHQL diff --git a/typings/main/globals/apollo-client/typings.json b/typings/main/globals/apollo-client/typings.json index b2d8262424b..d4e89fb2305 100644 --- a/typings/main/globals/apollo-client/typings.json +++ b/typings/main/globals/apollo-client/typings.json @@ -1,8 +1,8 @@ { "resolution": "main", "tree": { - "src": "/Users/sashko/git/apollo-client/ambient.d.ts", + "src": "/Users/dhaivatpandya/dev/apollo-client/ambient.d.ts", "raw": "file:./ambient.d.ts", - "typings": "/Users/sashko/git/apollo-client/ambient.d.ts" + "typings": "/Users/dhaivatpandya/dev/apollo-client/ambient.d.ts" } } diff --git a/typings/main/modules/lodash/index.d.ts b/typings/main/modules/lodash/index.d.ts index df22d03b322..bf8c7fc478c 100644 --- a/typings/main/modules/lodash/index.d.ts +++ b/typings/main/modules/lodash/index.d.ts @@ -18290,10 +18290,10 @@ export = _; interface Map {} } declare module 'lodash/index' { -import main = require('~lodash/index'); -export = main; +import alias = require('~lodash/index'); +export = alias; } declare module 'lodash' { -import main = require('~lodash/index'); -export = main; +import alias = require('~lodash/index'); +export = alias; } From c6522b31197d30ec80aba246260d5dd75952b354 Mon Sep 17 00:00:00 2001 From: Dhaivat Pandya Date: Wed, 20 Jul 2016 15:37:10 -0700 Subject: [PATCH 2/3] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 034e41339d1..be6cf91a169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Expect active development and potentially significant breaking changes in the `0 - Fixed a bug where fetching a query without an id and then later with an id resulted in an orphaned node within the store. [Issue #344](https://github.com/apollostack/apollo-client/issues/344) and [PR #389](https://github.com/apollostack/apollo-client/pull/389). - Fix typings for some refactored types, `ObservableQuery` and `WatchQueryOptions`. [PR #428](https://github.com/apollostack/apollo-client/pull/428) +- Added flattening of fragments within `createFragment`. [PR #437](https://github.com/apollostack/apollo-client/pull/437) and [Issue #421](https://github.com/apollostack/apollo-client/issues/421). ### v0.4.5 From 801b5b7f3189ace267ca9f8eb873b057a30a1ffe Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Wed, 20 Jul 2016 15:42:11 -0700 Subject: [PATCH 3/3] Move changelog entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62aaaca0671..f8cdfdb72da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,13 @@ Expect active development and potentially significant breaking changes in the `0 ### vNEXT +- Added flattening of fragments within `createFragment`. [PR #437](https://github.com/apollostack/apollo-client/pull/437) and [Issue #421](https://github.com/apollostack/apollo-client/issues/421). + ### v0.4.6 - Integrated the scheduler so that polling queries on the same polling interval are batched together. [PR #403](https://github.com/apollostack/apollo-client/pull/403) and [Issue #401](https://github.com/apollostack/apollo-client/issues/401). - Fixed a bug where fetching a query without an id and then later with an id resulted in an orphaned node within the store. [Issue #344](https://github.com/apollostack/apollo-client/issues/344) and [PR #389](https://github.com/apollostack/apollo-client/pull/389). - Fix typings for some refactored types, `ObservableQuery` and `WatchQueryOptions`. [PR #428](https://github.com/apollostack/apollo-client/pull/428) -- Added flattening of fragments within `createFragment`. [PR #437](https://github.com/apollostack/apollo-client/pull/437) and [Issue #421](https://github.com/apollostack/apollo-client/issues/421). ### v0.4.5