Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifically handle the connection directive when selecting store keys, fix #1779 #1801

Merged
merged 9 commits into from
Jun 24, 2017
16 changes: 9 additions & 7 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,13 @@ export class ObservableQuery<T> extends Observable<ApolloQueryResult<T>> {
throw new Error('updateQuery option is required. This function defines how to update the query data with the new results.');
}

let previous: any;
const previous = this.result();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has the same semantics wrt when it runs, which means it still doesn't fix the race condition of an update while the query is in flight.


return Promise.resolve()
.then(() => {
const qid = this.queryManager.generateQueryId();
let combinedOptions: any = null;

previous = this.currentResult().data;

if (fetchMoreOptions.query) {
// fetch a new query
combinedOptions = fetchMoreOptions;
Expand All @@ -260,19 +258,23 @@ export class ObservableQuery<T> extends Observable<ApolloQueryResult<T>> {
query: combinedOptions.query,
fetchPolicy: 'network-only',
} as WatchQueryOptions;

return this.queryManager.fetchQuery(qid, combinedOptions, FetchType.normal, this.queryId);
})
.then((fetchMoreResult) => {
}).then((fetchMoreResult) => {
return previous.then((prev) => {
return {prev, fetchMoreResult};
});
}).then(({prev, fetchMoreResult}) => {
const { data } = fetchMoreResult;
const reducer = fetchMoreOptions.updateQuery;
const mapFn = (previousResult: any, { variables }: {variables: any }) => {

const mapFn = (previousResult: any, { variables }: {variables: any }) => {
// TODO REFACTOR: reached max recursion depth (figuratively) when renaming queryVariables.
// Continue renaming to variables further down when we have time.
const queryVariables = variables;

return reducer(
previous, {
prev.data, {
fetchMoreResult: data as Object,
queryVariables,
});
Expand Down