Skip to content

Commit 2f82cbb

Browse files
ciaranschutteCiaran Schutte
andcommitted
Fed Search request timeouts (#889)
* move response object creation into module * change type structure for gql server * change resolver code based on new gql type * adjust agg type gql resolved response * add http resp helpers * change resolveAggregation code to batch processing * add nodeInfo to resolver * change resolver method to reducer with mutations * add type * fix typedef * format response object * comments and cleanup * add GQL request timeout with config option and default value --------- Co-authored-by: Ciaran Schutte <ciaranschutte@oicr.on.ca>
1 parent 820f22d commit 2f82cbb

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

modules/server/src/network/gql.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import axios, { AxiosRequestConfig } from 'axios';
22
import { ASTNode, print } from 'graphql';
33

44
/**
@@ -28,17 +28,21 @@ export const fetchGql = ({
2828
url,
2929
gqlQuery,
3030
variables,
31+
options,
3132
}: {
3233
url: string;
3334
gqlQuery: string;
3435
variables?: Record<string, string>;
36+
options?: { timeout: number };
3537
}) => {
36-
const options = {
38+
const timeout = options?.timeout || 10000;
39+
const axiosOptions: AxiosRequestConfig = {
3740
url,
3841
method: 'POST',
3942
headers: { 'Content-Type': 'application/json' },
4043
data: { query: gqlQuery, variables },
44+
signal: AbortSignal.timeout(timeout),
4145
};
4246

43-
return axios(options);
47+
return axios(axiosOptions);
4448
};

modules/server/src/network/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ import { fulfilledPromiseFilter, getAllTypes } from './util';
2828
const fetchRemoteSchema = async (
2929
config: NetworkAggregationConfigInput,
3030
): Promise<GQLTypeQueryResponse | undefined> => {
31-
const { graphqlUrl, documentType } = config;
31+
const { graphqlUrl, documentType, timeout } = config;
3232
try {
3333
const response = await fetchGql({
3434
url: graphqlUrl,
3535
gqlQuery: gqlAggregationTypeQuery,
3636
variables: { documentName: documentType },
37+
options: {
38+
timeout,
39+
},
3740
});
3841

3942
// axios response "data" field, graphql response "data" field

modules/server/src/network/resolvers/aggregations.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { gql } from 'apollo-server-core';
2+
import axios from 'axios';
23
import { DocumentNode } from 'graphql';
34
import { resolveAggregations } from '../aggregations';
45
import { fetchGql } from '../gql';
56
import { failure, isSuccess, success } from '../httpResponses';
6-
import { GQLResponse, supportedAggregationQueries } from '../queries';
7+
import { supportedAggregationQueries } from '../queries';
78
import { NetworkAggregation, NetworkAggregationConfig } from '../types';
8-
import { ASTtoString, fulfilledPromiseFilter } from '../util';
9+
import { ASTtoString } from '../util';
910
import { CONNECTION_STATUS, RemoteConnection } from './remoteConnections';
1011

1112
/**
@@ -29,6 +30,10 @@ const fetchData = async (query: NetworkQuery) => {
2930
return success(responseData);
3031
}
3132
} catch (error) {
33+
if (axios.isCancel(error)) {
34+
return failure(CONNECTION_STATUS.ERROR, `Request cancelled: ${url}`);
35+
}
36+
3237
const responseStatus = error.response.status;
3338
if (responseStatus === 404) {
3439
console.error(`Network failure: ${url}`);

modules/server/src/network/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export type NetworkAggregationConfigInput = {
88
documentType: string;
99
documentName: string;
1010
displayName: string;
11+
options: {
12+
timeout: number;
13+
};
1114
};
1215

1316
export type NetworkFieldType<T> = {

0 commit comments

Comments
 (0)