Skip to content

Commit

Permalink
remove all remaining mentions of forceFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
helfer committed Mar 7, 2017
1 parent b7bd087 commit 4fc0b64
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
14 changes: 6 additions & 8 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ export class ObservableQuery<T> extends Observable<ApolloQueryResult<T>> {
// will not end up hitting the server.
// See more: https://github.com/apollostack/apollo-client/issues/707
// Basically: is there a query in flight right now (modolo the next tick)?
const loading = (this.options.forceFetch && queryLoading)
|| (this.options.fetchPolicy === 'network-only' && queryLoading)
const loading = (this.options.fetchPolicy === 'network-only' && queryLoading)
|| (partial && this.options.fetchPolicy !== 'cache-only');

// if there is nothing in the query store, it means this query hasn't fired yet. Therefore the
Expand Down Expand Up @@ -191,10 +190,10 @@ export class ObservableQuery<T> extends Observable<ApolloQueryResult<T>> {
...this.variables,
};

// Override forceFetch for this call only
const combinedOptions = {
// Override fetchPolicy for this call only
const combinedOptions: WatchQueryOptions = {
...this.options,
forceFetch: true,
fetchPolicy: 'network-only',
};

return this.queryManager.fetchQuery(this.queryId, combinedOptions, FetchType.refetch)
Expand Down Expand Up @@ -311,9 +310,8 @@ export class ObservableQuery<T> extends Observable<ApolloQueryResult<T>> {
this.stopPolling();
}

// If forceFetch went from false to true or cachePolicy went from cache-only to something else
const tryFetch: boolean = (!oldOptions.forceFetch && opts.forceFetch)
|| (oldOptions.fetchPolicy !== 'network-only' && opts.fetchPolicy === 'network-only')
// If fetchPolicy went from cache-only to something else, or from something else to network-only
const tryFetch: boolean = (oldOptions.fetchPolicy !== 'network-only' && opts.fetchPolicy === 'network-only')
|| (oldOptions.fetchPolicy === 'cache-only' && opts.fetchPolicy !== 'cache-only')
|| false;

Expand Down
11 changes: 2 additions & 9 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,9 @@ export class QueryManager {
// network status for the query this is fetching for.
fetchMoreForQueryId?: string,
): Promise<ApolloQueryResult<T>> {
if (options.fetchPolicy) {
if (options.forceFetch) {
// XXX This is just here until we remove noFetch and forceFetch altogether.
throw new Error('cannot use fetchPolicy with noFetch or forceFetch set to true');
}
}

const {
variables = {},
forceFetch = false,
metadata = null,
fetchPolicy = 'cache-first', // cache-first is the default fetch policy.
} = options;
Expand All @@ -544,12 +537,12 @@ export class QueryManager {
const queryString = print(queryDoc);

let storeResult: any;
let needToFetch: boolean = forceFetch || fetchPolicy === 'network-only';
let needToFetch: boolean = fetchPolicy === 'network-only';

// If this is not a force fetch, we want to diff the query against the
// store before we fetch it from the network interface.
// TODO we hit the cache even if the policy is network-first. This could be unnecessary if the network is up.
if ( (fetchType !== FetchType.refetch && !forceFetch && fetchPolicy !== 'network-only')) {
if ( (fetchType !== FetchType.refetch && fetchPolicy !== 'network-only')) {
const { isMissing, result } = diffQueryAgainstStore({
query: queryDoc,
store: this.reduxRootSelector(this.store.getState()).data,
Expand Down
7 changes: 0 additions & 7 deletions src/core/watchQueryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ export interface ModifiableWatchQueryOptions {
* within the GraphQL query.
*/
variables?: { [key: string]: any };
/**
* Specifies whether the client should diff the query against the cache and only
* fetch the portions of it that aren't already available (it does this when forceFetch is
* false) or it should just fetch the entire query from the server and update the cache
* accordingly (it does this when forceFetch is true).
*/
forceFetch?: boolean;

/**
* The time interval (in milliseconds) on which this query should be
Expand Down

0 comments on commit 4fc0b64

Please sign in to comment.