Skip to content

Commit

Permalink
Merge pull request #1096 from apollostack/remove-fragments
Browse files Browse the repository at this point in the history
Remove fragments
  • Loading branch information
helfer authored Dec 25, 2016
2 parents 6c80bd6 + ca96a0a commit 0e1a93d
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 971 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Expect active development and potentially significant breaking changes in the `0

- ...

- Remove fragment option from query, watchQuery etc. [PR #1096](https://github.com/apollostack/apollo-client/pull/1096)

### 0.5.25
- Pass variables into result reducers [PR #1088](https://github.com/apollostack/apollo-client/pull/1088)
Expand Down
130 changes: 11 additions & 119 deletions src/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import {
} from './util/Observable';

import {
DeprecatedWatchQueryOptions,
DeprecatedSubscriptionOptions,
WatchQueryOptions,
SubscriptionOptions,
MutationOptions,
} from './core/watchQueryOptions';

Expand All @@ -61,12 +61,6 @@ import {
storeKeyNameFromFieldNameAndArgs,
} from './data/storeUtils';

import { createFragment } from './fragments';

import {
addFragmentsToDocument,
} from './queries/getFromAST';

import {
version,
} from './version';
Expand All @@ -85,12 +79,6 @@ function defaultReduxRootSelector(state: any) {
return state[DEFAULT_REDUX_ROOT_KEY];
}

// deprecation warning flags
let haveWarnedQuery = false;
let haveWarnedWatchQuery = false;
let haveWarnedMutation = false;
let haveWarnedSubscription = false;

/**
* This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries
* and mutations) to a GraphQL spec-compliant server over a {@link NetworkInterface} instance,
Expand Down Expand Up @@ -265,44 +253,17 @@ export default class ApolloClient {
* a description of store reactivity.
*
*/
public watchQuery(options: DeprecatedWatchQueryOptions): ObservableQuery {
public watchQuery(options: WatchQueryOptions): ObservableQuery {
this.initStore();

if (!this.shouldForceFetch && options.forceFetch) {
options = {
...options,
forceFetch: false,
} as DeprecatedWatchQueryOptions;
}

if (options.fragments && !haveWarnedWatchQuery && process.env.NODE_ENV !== 'production') {
console.warn(
'"fragments" option is deprecated and will be removed in the upcoming versions, ' +
'please refer to the documentation for how to define fragments: ' +
'http://dev.apollodata.com/react/fragments.html.',
);
/* istanbul ignore if */
if (process.env.NODE_ENV !== 'test') {
// When running tests, we want to print the warning every time
haveWarnedWatchQuery = true;
}
} as WatchQueryOptions;
}

// Register each of the fragments present in the query document. The point
// is to prevent fragment name collisions with fragments that are in the query
// document itself.
createFragment(options.query, undefined, true);

// We add the fragments to the document to pass only the document around internally.
const fullDocument = addFragmentsToDocument(options.query, options.fragments);

const realOptions = {
...options,
query: fullDocument,
};
delete realOptions.fragments;

return this.queryManager.watchQuery(realOptions);
return this.queryManager.watchQuery(options);
};

/**
Expand All @@ -314,7 +275,7 @@ export default class ApolloClient {
* how this query should be treated e.g. whether it is a polling query, whether it should hit the
* server at all or just resolve from the cache, etc.
*/
public query(options: DeprecatedWatchQueryOptions): Promise<ApolloQueryResult> {
public query(options: WatchQueryOptions): Promise<ApolloQueryResult> {
this.initStore();

// XXX what if I pass pollInterval? Will it just keep running?
Expand All @@ -324,37 +285,10 @@ export default class ApolloClient {
options = {
...options,
forceFetch: false,
} as DeprecatedWatchQueryOptions;
}

if (options.fragments && !haveWarnedQuery && process.env.NODE_ENV !== 'production') {
console.warn(
'"fragments" option is deprecated and will be removed in the upcoming versions, ' +
'please refer to the documentation for how to define fragments: ' +
'http://dev.apollodata.com/react/fragments.html.',
);
/* istanbul ignore if */
if (process.env.NODE_ENV !== 'test') {
// When running tests, we want to print the warning every time
haveWarnedQuery = true;
}
} as WatchQueryOptions;
}

// Register each of the fragments present in the query document. The point
// is to prevent fragment name collisions with fragments that are in the query
// document itself.
createFragment(options.query, undefined, true);

// We add the fragments to the document to pass only the document around internally.
const fullDocument = addFragmentsToDocument(options.query, options.fragments);

const realOptions = {
...options,
query: fullDocument,
};
delete realOptions.fragments;

return this.queryManager.query(realOptions);
return this.queryManager.query(options);
};

/**
Expand All @@ -370,9 +304,6 @@ export default class ApolloClient {
* @param options.variables An object that maps from the name of a variable as used in the mutation
* GraphQL document to that variable's value.
*
* @param options.fragments A list of fragments as returned by {@link createFragment}. These fragments
* can be referenced from within the GraphQL mutation document.
*
* @param options.optimisticResponse An object that represents the result of this mutation that will be
* optimistically stored before the server has actually returned a result. This is most often
* used for optimistic UI, where we want to be able to see the result of a mutation immediately,
Expand All @@ -391,55 +322,16 @@ export default class ApolloClient {
public mutate(options: MutationOptions): Promise<ApolloQueryResult> {
this.initStore();

if (options.fragments && !haveWarnedMutation && process.env.NODE_ENV !== 'production') {
console.warn(
'"fragments" option is deprecated and will be removed in the upcoming versions, ' +
'please refer to the documentation for how to define fragments: ' +
'http://dev.apollodata.com/react/fragments.html.',
);
/* istanbul ignore if */
if (process.env.NODE_ENV !== 'test') {
// When running tests, we want to print the warning every time
haveWarnedMutation = true;
}
}

// We add the fragments to the document to pass only the document around internally.
const fullDocument = addFragmentsToDocument(options.mutation, options.fragments);

const realOptions = {
...options,
mutation: fullDocument,
};
delete realOptions.fragments;

return this.queryManager.mutate(realOptions);
return this.queryManager.mutate(options);
};

public subscribe(options: DeprecatedSubscriptionOptions): Observable<any> {
public subscribe(options: SubscriptionOptions): Observable<any> {
this.initStore();

if (options.fragments && !haveWarnedSubscription && process.env.NODE_ENV !== 'production') {
console.warn(
'"fragments" option is deprecated and will be removed in the upcoming versions, ' +
'please refer to the documentation for how to define fragments: ' +
'http://dev.apollodata.com/react/fragments.html.',
);
/* istanbul ignore if */
if (process.env.NODE_ENV !== 'test') {
// When running tests, we want to print the warning every time
haveWarnedSubscription = true;
}
}

// We add the fragments to the document to pass only the document around internally.
const fullDocument = addFragmentsToDocument(options.query, options.fragments);

const realOptions = {
...options,
document: fullDocument,
document: options.query,
};
delete realOptions.fragments;
delete realOptions.query;

return this.queryManager.startGraphQLSubscription(realOptions);
Expand Down
7 changes: 1 addition & 6 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import { tryFunctionOrLogError } from '../util/errorHandling';

import { NetworkStatus } from '../queries/store';

import { addFragmentsToDocument } from '../queries/getFromAST';

import isEqual = require('lodash/isEqual');

export type ApolloCurrentResult = {
Expand Down Expand Up @@ -198,12 +196,9 @@ export class ObservableQuery extends Observable<ApolloQueryResult> {
};
}

// We add the fragments to the document to pass only the document around internally.
const fullQuery = addFragmentsToDocument(combinedOptions.query, combinedOptions.fragments);

combinedOptions = {
...combinedOptions,
query: fullQuery,
query: combinedOptions.query,
forceFetch: true,
} as WatchQueryOptions;
return this.queryManager.fetchQuery(qid, combinedOptions);
Expand Down
27 changes: 1 addition & 26 deletions src/core/watchQueryOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Document,
FragmentDefinition,
} from 'graphql';

import {
Expand Down Expand Up @@ -73,31 +72,9 @@ export interface WatchQueryOptions extends ModifiableWatchQueryOptions {
metadata?: any;
}

// This interface is deprecated because we no longer pass around fragments separately in the core.
export interface DeprecatedWatchQueryOptions extends ModifiableWatchQueryOptions {
/**
* A GraphQL document that consists of a single query to be sent down to the
* server.
*/
query: Document;

/**
* A list of fragments that are returned by {@link createFragment} which can be
* referenced from the query document.
*/
fragments?: FragmentDefinition[];

/**
* Arbitrary metadata stored in Redux with this query. Designed for debugging,
* developer tools, etc.
*/
metadata?: any;
}

export interface FetchMoreQueryOptions {
query?: Document;
variables?: { [key: string]: any };
fragments?: FragmentDefinition[];
}

export type SubscribeToMoreOptions = {
Expand All @@ -110,17 +87,15 @@ export type SubscribeToMoreOptions = {
onError?: (error: Error) => void;
};

export interface DeprecatedSubscriptionOptions {
export interface SubscriptionOptions {
query: Document;
variables?: { [key: string]: any };
fragments?: FragmentDefinition[];
};

export interface MutationOptions {
mutation: Document;
variables?: Object;
resultBehaviors?: MutationBehavior[];
fragments?: FragmentDefinition[];
optimisticResponse?: Object;
updateQueries?: MutationQueryReducersMap;
refetchQueries?: string[];
Expand Down
89 changes: 0 additions & 89 deletions src/fragments.ts

This file was deleted.

Loading

0 comments on commit 0e1a93d

Please sign in to comment.