Skip to content

Commit

Permalink
Merge branch 'master' into move-methods-to-observable
Browse files Browse the repository at this point in the history
  • Loading branch information
amandajliu committed Jul 7, 2016
2 parents 55ad6b8 + afb106f commit fd1750f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Expect active development and potentially significant breaking changes in the `0
### vNEXT
- moved refetch(), startPolling(), and stopPolling() methods from QuerySubscription to ObservableQuery [Issue #194] (https://github.com/apollostack/apollo-client/issues/194) and [PR #362] (https://github.com/apollostack/apollo-client/pull/362)

### v0.3.28

- Added missing export for the `addQueryMerging` method defined in the docs [here](http://docs.apollostack.com/apollo-client/network.html#addQueryMerging). [PR #364](https://github.com/apollostack/apollo-client/pull/364) and [Issue #363](https://github.com/apollostack/apollo-client/issues/363).
- Made sure `diffSelectionSetAgainstStore` will return any available data from the local cache if `throwOnMissingField` is `false`, even if some fields in the query are missing. This also means that the `returnPartialData` option of `watchQuery` will return partial data if some fields are missing in the cache, rather than an empty object. [Issue #359](https://github.com/apollostack/apollo-client/issues/359) and [PR #360](https://github.com/apollostack/apollo-client/pull/360).

### v0.3.27

- Removed dependency on `graphql` npm package, which was causing compilation errors in the React Native bundler. Issues [#261](https://github.com/apollostack/apollo-client/issues/261) [#163](https://github.com/apollostack/apollo-client/issues/163), [PR #357](https://github.com/apollostack/apollo-client/pull/357)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-client",
"version": "0.3.27",
"version": "0.3.28",
"description": "A simple yet functional GraphQL client.",
"main": "./lib/src/index.js",
"typings": "./lib/src/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/data/diffAgainstStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ export function diffSelectionSetAgainstStore({
included: includeField,
});

const resultFieldKey = resultKeyNameFromField(selection);
if (fieldIsMissing) {
// even if the field is not included, we want to keep it in the
// query that is sent to the server. So, we push it into the set of
// fields that is missing.
pushMissingField(selection);
} else if (includeField) {
const resultFieldKey = resultKeyNameFromField(selection);

}
if (includeField && fieldResult !== undefined) {
result[resultFieldKey] = fieldResult;
}
} else if (isInlineFragment(selection)) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
NetworkInterface,
createNetworkInterface,
addQueryMerging,
} from './networkInterface';

import {
Expand Down Expand Up @@ -65,6 +66,7 @@ import assign = require('lodash.assign');
// custom network interfaces can turn query ASTs into query strings as needed.
export {
createNetworkInterface,
addQueryMerging,
createApolloStore,
createApolloReducer,
readQueryFromStore,
Expand Down
64 changes: 63 additions & 1 deletion test/diffAgainstStore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { assert } from 'chai';

import { diffQueryAgainstStore } from '../src/data/diffAgainstStore';
import {
diffQueryAgainstStore,
diffSelectionSetAgainstStore,
} from '../src/data/diffAgainstStore';
import { writeQueryToStore } from '../src/data/writeToStore';
import { printQueryForMissingData } from '../src/queryPrinting';
import { getQueryDefinition } from '../src/queries/getFromAST';


import {
getIdField,
Expand Down Expand Up @@ -279,4 +284,61 @@ describe('diffing queries against the store', () => {
`);
assert.deepEqual(store['1'], result.people_one);
});

it('returns available fields if throwOnMissingField is false', () => {
const firstQuery = gql`
{
people_one(id: "1") {
__typename
id
name
}
}
`;

const firstResult = {
people_one: {
__typename: 'Person',
id: 'lukeId',
name: 'Luke Skywalker',
},
};

const store = writeQueryToStore({
result: firstResult,
query: firstQuery,
});

const queryWithMissingField = gql`
{
people_one(id: "1") {
name
age
}
}
`;

const { result } = diffSelectionSetAgainstStore({
store,
rootId: 'ROOT_QUERY',
selectionSet: getQueryDefinition(queryWithMissingField).selectionSet,
variables: null,
throwOnMissingField: false,
});

assert.deepEqual(result, {
people_one: {
name: 'Luke Skywalker',
},
});
assert.throws(function() {
diffSelectionSetAgainstStore({
store,
rootId: 'ROOT_QUERY',
selectionSet: getQueryDefinition(queryWithMissingField).selectionSet,
variables: null,
throwOnMissingField: true,
});
});
});
});

0 comments on commit fd1750f

Please sign in to comment.