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

Adding typescript definition for 'this' on Middleware and Afterware apply functions. #1372

Merged
merged 8 commits into from
Mar 14, 2017
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Expect active development and potentially significant breaking changes in the `0
- Fix: make sure maybeDeepFreeze is called on results returned from setVariables and refetch [PR #1362](https://github.com/apollographql/apollo-client/pull/1362)
- Fix: use setTimeout to throw uncaught errors in observer.next and observer.error[PR #1367](https://github.com/apollographql/apollo-client/pull/1367)
- Remove returnPartialData option [PR #1370](https://github.com/apollographql/apollo-client/pull/1370)

- Update TypeScript Middleware and Afterware interfaces to include a datatype for 'this' in apply function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure to add the PR number here!


### 0.10.1
- Address deprecation warnings coming from `graphql-tag` [graphql-tag#54](https://github.com/apollographql/graphql-tag/issues/54)
Expand Down
6 changes: 4 additions & 2 deletions src/transport/afterware.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { NetworkInterface } from './networkInterface';

export interface AfterwareResponse {
response: Response;
options: RequestInit;
}

export interface AfterwareInterface {
applyAfterware(response: AfterwareResponse, next: Function): any;
applyAfterware(this: NetworkInterface, response: AfterwareResponse, next: Function): any;
}

export interface BatchAfterwareResponse {
Expand All @@ -13,5 +15,5 @@ export interface BatchAfterwareResponse {
}

export interface BatchAfterwareInterface {
applyBatchAfterware(response: BatchAfterwareResponse, next: Function): any;
applyBatchAfterware(this: NetworkInterface, response: BatchAfterwareResponse, next: Function): any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the correct type or could it be more specific (BatchNetworkInterface)?

}
6 changes: 3 additions & 3 deletions src/transport/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Request } from './networkInterface';
import { Request, NetworkInterface } from './networkInterface';

export interface MiddlewareRequest {
request: Request;
options: RequestInit;
}

export interface MiddlewareInterface {
applyMiddleware(request: MiddlewareRequest, next: Function): void;
applyMiddleware(this: NetworkInterface, request: MiddlewareRequest, next: Function): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Also this type. Could it be more specific?

}

export interface BatchMiddlewareRequest {
Expand All @@ -15,5 +15,5 @@ export interface BatchMiddlewareRequest {
}

export interface BatchMiddlewareInterface {
applyBatchMiddleware(request: BatchMiddlewareRequest, next: Function): void;
applyBatchMiddleware(this: NetworkInterface, request: BatchMiddlewareRequest, next: Function): void;
}