Skip to content

Commit 5ffe5e9

Browse files
ciaranschutteCiaran Schutte
andauthored
Feat/fed search cleanup (#920)
* add placeholder * Adjust config template example and file * remove unused arranger constructor param * reorder constants file, parse env var * update arranger network config type * type, add gql server types * graphqlRoutes, remove unused import, export func * resolver creation, improve TS usage, split functionality into distinct files, improve usage' * add surrounding brackets for func * cleanup schema resolvers --------- Co-authored-by: Ciaran Schutte <ciaranschutte@oicr.on.ca>
1 parent 52ed91e commit 5ffe5e9

File tree

18 files changed

+190
-127
lines changed

18 files changed

+190
-127
lines changed

modules/server/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ npm run prepare
2121

2222
## Federated Search
2323

24+
[Placeholder]
25+
2426
### Config
2527

26-
[Placeholder]
28+
[Placeholder]

modules/server/configTemplates/configs.json.schema

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,13 @@
7373
"maxResultsWindow": 10000,
7474
"rowIdFieldName": "analysis.analysis_id"
7575
}
76+
"network": {
77+
"servers": [
78+
{
79+
"displayName": "Toronto",
80+
"graphqlUrl": "http://<URL>/graphql",
81+
"documentType": "file"
82+
}
83+
]
84+
}
7685
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
{
22
"network": {
3-
"servers": [
4-
{
5-
"displayName": "Toronto",
6-
"graphqlUrl": "http://.../graphql",
7-
"documentType": "file"
8-
}
9-
]
3+
"servers": []
104
}
115
}

modules/server/src/app.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ export default async function (rootPath = '') {
1212

1313
/**
1414
* @param {boolean} enableAdmin
15-
* @param {boolean} enableDocumentHits - enables including "hits" property in the GQL response
1615
*/
1716
return arranger({
1817
enableAdmin: ENV_CONFIG.ENABLE_ADMIN,
19-
enableDocumentHits: ENV_CONFIG.ENABLE_DOCUMENT_HITS,
2018
}).then((router) => {
2119
app.use(router);
2220

modules/server/src/config/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ export const ALLOW_CUSTOM_MAX_DOWNLOAD_ROWS = stringToBool(
55
);
66
export const CONFIG_FILES_PATH = process.env.CONFIG_PATH || './configs';
77
export const DATA_MASK_MIN_THRESHOLD =
8-
process.env.DATA_MASK_MIN_THRESHOLD || Number.MAX_SAFE_INTEGER;
8+
stringToNumber(process.env.DATA_MASK_MIN_THRESHOLD) || Number.MAX_SAFE_INTEGER;
99
export const DEBUG_MODE = stringToBool(process.env.DEBUG);
1010
export const DOCUMENT_TYPE = process.env.DOCUMENT_TYPE || '';
1111
export const DOWNLOAD_STREAM_BUFFER_SIZE =
1212
stringToNumber(process.env.DOWNLOAD_STREAM_BUFFER_SIZE) || 2000;
1313
export const ENABLE_ADMIN = stringToBool(process.env.ENABLE_ADMIN);
1414
export const ENABLE_DOCUMENT_HITS = stringToBool(process.env.ENABLE_DOCUMENT_HITS);
1515
export const ENABLE_LOGS = stringToBool(process.env.ENABLE_LOGS);
16+
export const ENABLE_NETWORK_AGGREGATION = stringToBool(process.env.ENABLE_NETWORK_AGGREGATION);
1617
export const ES_ARRANGER_SET_INDEX = process.env.ES_ARRANGER_SET_INDEX || 'arranger-sets';
1718
export const ES_ARRANGER_SET_TYPE = process.env.ES_ARRANGER_SET_TYPE || 'arranger-sets';
1819
export const ES_HOST = process.env.ES_HOST || 'http://127.0.0.1:9200';
@@ -27,4 +28,3 @@ export const PING_MS = stringToNumber(process.env.PING_MS) || 2200;
2728
export const PING_PATH = process.env.PING_PATH || '/ping';
2829
export const PORT = stringToNumber(process.env.PORT) || 5050;
2930
export const ROW_ID_FIELD_NAME = process.env.ROW_ID_FIELD_NAME || 'id';
30-
export const ENABLE_NETWORK_AGGREGATION = stringToBool(process.env.ENABLE_NETWORK_AGGREGATION);

modules/server/src/config/types.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// TODO: will gradually tighten these as we migrate to TS
22

33
import { ES_TYPES } from '@/mapping/esToAggTypeMap';
4-
import { DOCUMENT_TYPE } from './constants';
54

65
export const ConfigOptionalProperties = {
76
DOWNLOADS: 'downloads',
@@ -55,7 +54,7 @@ export const TableProperties = {
5554
ROW_ID_FIELD_NAME: 'rowIdFieldName',
5655
} as const;
5756

58-
export const NetworkAggregationProperties = {
57+
const NetworkAggregationProperties = {
5958
GRAPHQL_URL: 'graphqlUrl',
6059
DOCUMENT_TYPE: 'documentType',
6160
DISPLAY_NAME: 'displayName',
@@ -151,10 +150,12 @@ export interface TableConfigsInterface {
151150
[ConfigProperties.ROW_ID_FIELD_NAME]?: string;
152151
}
153152

154-
export interface NetworkAggregationInterface {
155-
[NetworkAggregationProperties.GRAPHQL_URL]: string;
156-
[NetworkAggregationProperties.DOCUMENT_TYPE]: string;
157-
[NetworkAggregationProperties.DISPLAY_NAME]: string;
153+
interface NetworkAggregationInterface {
154+
servers: {
155+
[NetworkAggregationProperties.GRAPHQL_URL]: string;
156+
[NetworkAggregationProperties.DOCUMENT_TYPE]: string;
157+
[NetworkAggregationProperties.DISPLAY_NAME]: string;
158+
}[];
158159
}
159160

160161
export interface ConfigObject {
@@ -165,7 +166,7 @@ export interface ConfigObject {
165166
[ConfigProperties.INDEX]: string;
166167
[ConfigProperties.MATCHBOX]: any[];
167168
[ConfigProperties.TABLE]: TableConfigsInterface;
168-
[ConfigProperties.NETWORK_AGGREGATION]: NetworkAggregationInterface[];
169+
[ConfigProperties.NETWORK_AGGREGATION]: NetworkAggregationInterface;
169170
}
170171

171172
export interface FieldFromMapping {

modules/server/src/gqlServer.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Client } from '@elastic/elasticsearch';
2+
import { GraphQLResolveInfo } from 'graphql';
3+
4+
export type Context = {
5+
esClient: Client;
6+
};
7+
8+
export type ResolverOutput<T> = T | Promise<T>;
9+
10+
/**
11+
* GQL resolver
12+
*
13+
* @param root - Parent object of a query.
14+
* @param args - Query arguments.
15+
* @param context - Context passed to apollo-server for queries.
16+
* @param info - GraphQL info object.
17+
* @return Returns resolved value;
18+
*/
19+
export type Resolver<Root = {}, QueryArgs = Object, ReturnValue = undefined> = (
20+
root: Root,
21+
args: QueryArgs,
22+
context: Context,
23+
info: GraphQLResolveInfo,
24+
) => ResolverOutput<ReturnValue> | ResolverOutput<ReturnValue>;

modules/server/src/graphqlRoutes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import expressPlayground from 'graphql-playground-middleware-express';
55

66
import { mergeSchemas } from '@graphql-tools/schema';
77
import getConfigObject, { initializeSets } from './config';
8-
import { DEBUG_MODE, ENABLE_NETWORK_AGGREGATION, ES_PASS, ES_USER } from './config/constants';
8+
import { DEBUG_MODE, ES_PASS, ES_USER } from './config/constants';
99
import { ConfigProperties } from './config/types';
1010
import { addMappingsToTypes, extendFields, fetchMapping } from './mapping';
1111
import { extendColumns, extendFacets, flattenMappingToFields } from './mapping/extendMapping';
@@ -243,7 +243,7 @@ const createEndpoint = async ({ esClient, graphqlOptions = {}, mockSchema, schem
243243
return router;
244244
};
245245

246-
const createSchemasFromConfigs = async ({
246+
export const createSchemasFromConfigs = async ({
247247
configsSource = '',
248248
enableAdmin,
249249
enableDocumentHits,
@@ -272,7 +272,7 @@ const createSchemasFromConfigs = async ({
272272

273273
const schemasToMerge = [schema];
274274

275-
/*
275+
/**
276276
* Federated Network Search
277277
*/
278278
if (enableNetworkAggregation) {

modules/server/src/mapping/createConnectionTypeDefs.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import mappingToAggsType from './mappingToAggsType';
22

3-
export default ({ type, fields = '', createStateTypeDefs = true, showRecords }) => {
4-
const dataMaskingType = !showRecords ? 'type DataMasking { thresholdValue: Int }' : '';
3+
const createConnectionType = (enableDocumentHits) => {
4+
return `type ${type.name}Connection {
5+
total: Int!
6+
${enableDocumentHits ? `edges: [${type.name}Edge]` : ''}
7+
}`;
8+
};
9+
10+
const createDataMaskingType = (enableDocumentHits) => {
11+
return !enableDocumentHits ? `type DataMasking { thresholdValue: Int }` : '';
12+
};
513

14+
export default ({ type, fields = '', createStateTypeDefs = true, enableDocumentHits }) => {
615
return `
716
type ${type.name} {
817
aggregations(
@@ -34,12 +43,10 @@ export default ({ type, fields = '', createStateTypeDefs = true, showRecords })
3443
${mappingToAggsType(type.mapping)}
3544
}
3645
37-
${dataMaskingType}
46+
${createDataMaskingType(enableDocumentHits)}
3847
39-
type ${type.name}Connection {
40-
total: Int!
41-
${showRecords ? `edges: [${type.name}Edge]` : ''}
42-
}
48+
${createConnectionType(enableDocumentHits)}
49+
4350
4451
type ${type.name}Edge {
4552
searchAfter: JSON

modules/server/src/mapping/mappingToFields.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import mappingToObjectTypes from './mappingToObjectTypes';
66
import mappingToScalarFields from './mappingToScalarFields';
77

88
const mappingToFields = ({ enableDocumentHits, type, parent }) => {
9-
const showRecords = enableDocumentHits;
109
return [
1110
mappingToObjectTypes(type.name, type.mapping, parent, type.extendedFields),
1211
Object.entries(type.mapping)
@@ -29,7 +28,7 @@ const mappingToFields = ({ enableDocumentHits, type, parent }) => {
2928
type.customFields,
3029
],
3130
createStateTypeDefs: 'createState' in type ? type.createState : true,
32-
showRecords,
31+
enableDocumentHits,
3332
}),
3433
].join();
3534
};

0 commit comments

Comments
 (0)