Skip to content

Commit

Permalink
flow comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dr3 committed Feb 4, 2024
1 parent b723ca3 commit 5c6bc02
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/RelayRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export default class RelayRequest {
}

clone(): RelayRequest {
// $FlowFixMe
const newRequest = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
newRequest.fetchOpts = { ...this.fetchOpts
};
Expand All @@ -117,4 +116,4 @@ export default class RelayRequest {
return (newRequest as any);
}

}
}
3 changes: 1 addition & 2 deletions src/RelayRequestBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export default class RelayRequestBatch {
}

clone(): RelayRequestBatch {
// $FlowFixMe
const newRequest = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
newRequest.fetchOpts = { ...this.fetchOpts
};
Expand All @@ -72,4 +71,4 @@ export default class RelayRequestBatch {
return this.prepareBody();
}

}
}
3 changes: 1 addition & 2 deletions src/RelayResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ export default class RelayResponse {
}

clone(): RelayResponse {
// $FlowFixMe
return Object.assign(Object.create(Object.getPrototypeOf(this)), this);
}

toString(): string {
return [`Response:`, ` Url: ${this.url || ''}`, ` Status code: ${this.status || ''}`, ` Status text: ${this.statusText || ''}`, ` Response headers: ${JSON.stringify(this.headers) || ''}`, ` Response body: ${JSON.stringify(this.json) || ''}`].join('\n');
}

}
}
4 changes: 1 addition & 3 deletions src/fetchWithMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const convertResponse: (next: MiddlewareRawNextFn) => MiddlewareNextFn = next =>
export default function fetchWithMiddleware(req: RelayRequestAny, middlewares: Middleware[], // works with RelayResponse
rawFetchMiddlewares: MiddlewareRaw[], // works with raw fetch response
noThrow?: boolean): Promise<RelayResponse> {
// $FlowFixMe
const wrappedFetch: MiddlewareNextFn = compose(...middlewares, convertResponse, ...rawFetchMiddlewares)((runFetch as any));
return wrappedFetch(req).then(res => {
if (!noThrow && (!res || res.errors || !res.data)) {
Expand All @@ -59,7 +58,6 @@ function compose(...funcs) {
} else {
const last = funcs[funcs.length - 1];
const rest = funcs.slice(0, -1);
// $FlowFixMe - Suppress error about promise not being callable
return (...args) => rest.reduceRight((composed, f) => f((composed as any)), last(...args));
}
}
}
3 changes: 1 addition & 2 deletions src/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default function authMiddleware(opts?: AuthMiddlewareOpts): Middleware {
let tokenRefreshInProgress = null;
return next => async req => {
try {
// $FlowFixMe
const token = await (isFunction(tokenOrThunk) ? tokenOrThunk(req) : tokenOrThunk);

if (!token && tokenRefreshPromise && !allowEmptyToken) {
Expand Down Expand Up @@ -77,4 +76,4 @@ export default function authMiddleware(opts?: AuthMiddlewareOpts): Middleware {
throw e;
}
};
}
}
3 changes: 1 addition & 2 deletions src/middlewares/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ async function sendRequests(requestList: RequestWrapper[], next, opts) {
} else if (requestList.length > 1) {
// SEND AS BATCHED QUERY
const batchRequest = new RelayRequestBatch(requestList.map(wrapper => wrapper.req));
// $FlowFixMe
const url = await (isFunction(opts.batchUrl) ? opts.batchUrl(requestList) : opts.batchUrl);
batchRequest.setFetchOption('url', url);
const {
Expand Down Expand Up @@ -235,4 +234,4 @@ function createSingleResponse(batchResponse: RelayResponse, json: any): RelayRes
const res = batchResponse.clone();
res.processJsonData(data);
return res;
}
}
3 changes: 1 addition & 2 deletions src/middlewares/legacyBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ async function sendRequests(requestMap: BatchRequestMap, next, opts) {
} else if (ids.length > 1) {
// SEND AS BATCHED QUERY
const batchRequest = new RelayRequestBatch(ids.map(id => requestMap[id].req));
// $FlowFixMe
const url = await (isFunction(opts.batchUrl) ? opts.batchUrl(requestMap) : opts.batchUrl);
batchRequest.setFetchOption('url', url);
const {
Expand Down Expand Up @@ -219,4 +218,4 @@ function createSingleResponse(batchResponse: RelayResponse, json: any): RelayRes
const res = batchResponse.clone();
res.processJsonData(data);
return res;
}
}

0 comments on commit 5c6bc02

Please sign in to comment.