Skip to content

Commit

Permalink
Merge pull request #303 from apollostack/streamline-imports
Browse files Browse the repository at this point in the history
Streamline API
  • Loading branch information
Sashko Stubailo authored Jun 23, 2016
2 parents 982b7f7 + 8883f9e commit 8b626b8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Expect active development and potentially significant breaking changes in the `0

### vNEXT

- Exported `addTypename` query transform directly from `apollo-client` so that it doesn't need to be imported from a submodule. [PR #303](https://github.com/apollostack/apollo-client/pull/303)
- Made network interfaces from `createNetworkInterface` have batching capability by default. [PR #303](https://github.com/apollostack/apollo-client/pull/303)

### v0.3.18

- Solved an issue that occurred when merging two queries with exactly the same query document [Issue #296](https://github.com/apollostack/apollo-client/issues/296) and [PR #299](https://github.com/apollostack/apollo-client/pull/299)
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {

import {
QueryTransformer,
addTypenameToSelectionSet,
} from './queries/queryTransform';

import isUndefined = require('lodash.isundefined');
Expand All @@ -42,6 +43,7 @@ export {
createApolloReducer,
readQueryFromStore,
readFragmentFromStore,
addTypenameToSelectionSet as addTypename,
};

export default class ApolloClient {
Expand Down
17 changes: 8 additions & 9 deletions src/networkInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ export interface PrintedRequest {
}

export interface NetworkInterface {
[others: string]: any;
query(request: Request): Promise<GraphQLResult>;
}

export interface BatchedNetworkInterface extends NetworkInterface {
batchQuery(requests: Request[]): Promise<GraphQLResult[]>;
}

export interface HTTPNetworkInterface extends NetworkInterface {
export interface HTTPNetworkInterface extends BatchedNetworkInterface {
_uri: string;
_opts: RequestInit;
_middlewares: MiddlewareInterface[];
Expand All @@ -56,18 +57,14 @@ export interface RequestAndOptions {
// it into a network interface that supports batching by composing/merging queries in to one
// query.
export function addQueryMerging(networkInterface: NetworkInterface): BatchedNetworkInterface {
return {
query(request: Request): Promise<GraphQLResult> {
return networkInterface.query(request);
},

return assign(networkInterface, {
batchQuery(requests: Request[]): Promise<GraphQLResult[]> {
const composedRequest = mergeRequests(requests);
return this.query(composedRequest).then((composedResult) => {
return unpackMergedResult(composedResult, requests);
});
},
};
}) as BatchedNetworkInterface;
}

export function printRequest(request: Request): PrintedRequest {
Expand Down Expand Up @@ -161,11 +158,13 @@ export function createNetworkInterface(uri: string, opts: RequestInit = {}): HTT
});
}

return {
// createNetworkInterface has batching ability by default, which is not used unless the
// `shouldBatch` option is passed to apollo-client
return addQueryMerging({
_uri,
_opts,
_middlewares,
query,
use,
};
}) as HTTPNetworkInterface;
}

0 comments on commit 8b626b8

Please sign in to comment.