Skip to content

Commit

Permalink
Merge pull request #437 from apollostack/fragment_flattening
Browse files Browse the repository at this point in the history
Added the fragment flattening
  • Loading branch information
Sashko Stubailo authored Jul 20, 2016
2 parents f3cafd5 + 801b5b7 commit d3075a9
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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).
Expand Down
10 changes: 10 additions & 0 deletions ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions test/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
10 changes: 10 additions & 0 deletions typings/browser/globals/apollo-client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions typings/browser/globals/apollo-client/typings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 4 additions & 4 deletions typings/browser/modules/lodash/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18290,10 +18290,10 @@ export = _;
interface Map<K, V> {}
}
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;
}
15 changes: 10 additions & 5 deletions typings/main/globals/apollo-client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions typings/main/globals/apollo-client/typings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 4 additions & 4 deletions typings/main/modules/lodash/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18290,10 +18290,10 @@ export = _;
interface Map<K, V> {}
}
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;
}

0 comments on commit d3075a9

Please sign in to comment.