Skip to content
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
lerna-debug.log
.groovylintrc.json
.vscode/*.log
.vscode/launch.json

**/dist
**/node_modules
Expand Down
6 changes: 6 additions & 0 deletions modules/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ Build (required before publish):
```
npm run prepare
```

## Federated Search

### Config

[Placeholder]
11 changes: 11 additions & 0 deletions modules/server/configTemplates/network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"network": {
"servers": [
{
"displayName": "Toronto",
"graphqlUrl": "http://.../graphql",
"documentType": "file"
}
]
}
}
15 changes: 15 additions & 0 deletions modules/server/src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// TODO: will gradually tighten these as we migrate to TS

import { ES_TYPES } from '@/mapping/esToAggTypeMap';
import { DOCUMENT_TYPE } from './constants';

export const ConfigOptionalProperties = {
DOWNLOADS: 'downloads',
MATCHBOX: 'matchbox',
NETWORK_AGGREGATION: 'network',
} as const;

export const ConfigRequiredProperties = {
Expand Down Expand Up @@ -53,6 +55,12 @@ export const TableProperties = {
ROW_ID_FIELD_NAME: 'rowIdFieldName',
} as const;

export const NetworkAggregationProperties = {
GRAPHQL_URL: 'graphqlUrl',
DOCUMENT_TYPE: 'documentType',
DISPLAY_NAME: 'displayName',
} as const;

//////////////////////////////////

export const ConfigProperties = {
Expand Down Expand Up @@ -143,6 +151,12 @@ export interface TableConfigsInterface {
[ConfigProperties.ROW_ID_FIELD_NAME]?: string;
}

export interface NetworkAggregationInterface {
[NetworkAggregationProperties.GRAPHQL_URL]: string;
[NetworkAggregationProperties.DOCUMENT_TYPE]: string;
[NetworkAggregationProperties.DISPLAY_NAME]: string;
}

export interface ConfigObject {
[ConfigProperties.DOCUMENT_TYPE]: string;
[ConfigProperties.DOWNLOADS]?: DownloadsConfigsInterface;
Expand All @@ -151,6 +165,7 @@ export interface ConfigObject {
[ConfigProperties.INDEX]: string;
[ConfigProperties.MATCHBOX]: any[];
[ConfigProperties.TABLE]: TableConfigsInterface;
[ConfigProperties.NETWORK_AGGREGATION]: NetworkAggregationInterface[];
}

export interface FieldFromMapping {
Expand Down
34 changes: 19 additions & 15 deletions modules/server/src/config/utils/getConfigFromFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,27 @@ const getConfigFromFiles = (

const configObj = (files as [string, any][]).reduce(
(configsAcc: Partial<ConfigObject>, [fileName, fileData]) => {
const fileDataJSON = JSON.parse(fileData);
try {
const fileDataJSON = JSON.parse(fileData);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

failure can be empty file


if (fileDataJSON?.[ConfigProperties.TABLE]?.[ConfigProperties.DEFAULT_SORTING]) {
return merge({}, configsAcc, fileDataJSON, {
[ConfigProperties.TABLE]: {
...fileDataJSON[ConfigProperties.TABLE],
[ConfigProperties.DEFAULT_SORTING]: fileDataJSON[ConfigProperties.TABLE][
ConfigProperties.DEFAULT_SORTING
].map((sorting: SortingConfigsInterface) => ({
...sorting,
desc: sorting.desc || false,
})),
},
});
}
if (fileDataJSON?.[ConfigProperties.TABLE]?.[ConfigProperties.DEFAULT_SORTING]) {
return merge({}, configsAcc, fileDataJSON, {
[ConfigProperties.TABLE]: {
...fileDataJSON[ConfigProperties.TABLE],
[ConfigProperties.DEFAULT_SORTING]: fileDataJSON[ConfigProperties.TABLE][
ConfigProperties.DEFAULT_SORTING
].map((sorting: SortingConfigsInterface) => ({
...sorting,
desc: sorting.desc || false,
})),
},
});
}

return merge({}, configsAcc, fileDataJSON);
return merge({}, configsAcc, fileDataJSON);
} catch (e) {
throw new Error('Could not parse the provided configuration files');
}
},
configsFromEnv,
);
Expand Down
31 changes: 24 additions & 7 deletions modules/server/src/graphqlRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { Router } from 'express';
import expressPlayground from 'graphql-playground-middleware-express';

import getConfigObject, { initializeSets } from './config';
import { DEBUG_MODE, ES_USER, ES_PASS } from './config/constants';
import { DEBUG_MODE, ENABLE_NETWORK_AGGREGATION, ES_PASS, ES_USER } from './config/constants';
import { ConfigProperties } from './config/types';
import { addMappingsToTypes, extendFields, fetchMapping } from './mapping';
import { extendColumns, extendFacets, flattenMappingToFields } from './mapping/extendMapping';
import { createSchemaFromNetworkConfig, mergeSchemas } from './network';
import makeSchema from './schema';

const getESMapping = async (esClient, index) => {
Expand Down Expand Up @@ -249,19 +250,35 @@ export const createSchemasFromConfigs = async ({
configsFromFiles,
);

const commonFields = { fieldsFromMapping, typesWithMappings };

const { mockSchema, schema } = await createSchema({
enableAdmin,
getServerSideFilter,
graphqlOptions,
types: typesWithMappings,
});

return {
fieldsFromMapping,
mockSchema,
schema,
typesWithMappings,
};
if (false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

temp until profile config is added

const { networkSchema } = await createSchemaFromNetworkConfig({
networkConfig: configsFromFiles[ConfigProperties.NETWORK_AGGREGATION],
});
const [mergedSchema, mergedMockSchema] = mergeSchemas({
local: { schema, mockSchema },
network: { schema: networkSchema, mockSchema: networkMockSchema },
});
return {
...commonFields,
schema: mergedSchema,
mockSchema: mergedMockSchema,
};
} else {
return {
...commonFields,
mockSchema,
schema,
};
}
Comment on lines +270 to +281
Copy link
Contributor Author

@ciaranschutte ciaranschutte Jun 5, 2024

Choose a reason for hiding this comment

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

personally preferring the readability of verbose returns and keeping variables as const instead of mutating vars.

} catch (error) {
const message = error?.message || error;
console.info('\n------\nError thrown while creating the GraphQL schemas.');
Expand Down
10 changes: 10 additions & 0 deletions modules/server/src/network/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NetworkAggregationInterface } from '@/config/types';

export const createSchemaFromNetworkConfig = ({
networkConfig,
}: {
networkConfig: NetworkAggregationInterface[];
}) => {
console.log('network config', networkConfig);
};
export const mergeSchemas = () => {};
Comment on lines +1 to +10
Copy link
Contributor Author

Choose a reason for hiding this comment

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

placeholders.