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

Fix 920 #922

Merged
merged 5 commits into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Expect active development and potentially significant breaking changes in the `0
### 0.5.5
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually just put the changelog entries under "vNEXT" until we make a release, because we don't know if the next one will be 0.5.5 or 0.6.0 until we release it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I will make the change.

- Add back missing dependency on lodash.isequal that was mistakenly removed in 0.5.4 [#925](https://github.com/apollostack/apollo-client/pull/925)
- Implement cache redirects with custom resolvers [PR #921](https://github.com/apollostack/apollo-client/pull/921)
- Fix issue that caused `createBatchingNetworkInterface` unable to specify request headers by `opts` or `applyMiddleware`. [PR #922](https://github.com/apollostack/apollo-client/pull/922) [Issue #920](https://github.com/apollostack/apollo-client/issues/920)

### 0.5.4
- Fix a bug that caused apollo-client to catch errors thrown in Observer.next callbacks [PR #910](https://github.com/apollostack/apollo-client/pull/910)
Expand Down
9 changes: 5 additions & 4 deletions src/transport/batchedNetworkInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ export class HTTPBatchedNetworkInterface extends HTTPFetchNetworkInterface {
return printRequest(request);
});

return fetch(this._uri, assign({}, this._opts, options, {
return fetch(this._uri, assign({}, this._opts, {
body: JSON.stringify(printedRequests),
headers: assign({}, options.headers, {
method: 'POST',
}, options, {
headers: assign({}, {
Accept: '*/*',
'Content-Type': 'application/json',
}),
method: 'POST',
}, options.headers),
}));
};
}
Expand Down
19 changes: 17 additions & 2 deletions test/batchedNetworkInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ describe('HTTPBatchedNetworkInterface', () => {

fetch = fetchFunc || createMockFetch({
url,
opts: merge(opts, {
opts: merge({
body: JSON.stringify(printedRequests),
headers: {
Accept: '*/*',
'Content-Type': 'application/json',
},
method: 'POST',
}),
}, opts),
result: createMockedIResponse(resultList),
});

Expand Down Expand Up @@ -223,4 +223,19 @@ describe('HTTPBatchedNetworkInterface', () => {
middlewares: [ changeMiddleware ],
});
});

it('opts should be able to modify request headers and method (#920)', () => {
const customHeaders: { [index: string]: string } = {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'x-www-form-urlencoded',
};
const options = { method: 'GET', headers: customHeaders };
return assertRoundtrip({
requestResultPairs: [{
request: { query: authorQuery },
result: authorResult,
}],
opts: options,
});
});
});
15 changes: 14 additions & 1 deletion test/mocks/mockFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class MockFetch {
public fetchParamsToKey(url: string, opts: RequestInit): string {
return JSON.stringify({
url,
opts,
opts: sortByKey(opts),
});
}

Expand All @@ -80,6 +80,19 @@ export class MockFetch {
}
}

function sortByKey(obj: any): Object {
return Object.keys(obj).sort().reduce(
(ret: any, key: string): Object => (
Object.assign({
[key]: Object.prototype.toString.call(obj[key]).slice(8, -1) === 'Object'
? sortByKey(obj[key])
: obj[key],
}, ret)
),
{},
);
}

export function createMockFetch(...mockedResponses: MockedFetchResponse[]) {
return new MockFetch(...mockedResponses).getFetch();
}