Thanks to visit codestin.com
Credit goes to github.com

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
4 changes: 2 additions & 2 deletions src/server/__tests__/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ describe('Schema', () => {

const expectedMappingSchema = `
type Mapping {
subject: [String]
file: [String]
subject(searchInput: String): [String]
file(searchInput: String): [String]
}`;
test('could create mapping schema', async () => {
const mappingSchema = getMappingSchema(config.esConfig);
Expand Down
12 changes: 8 additions & 4 deletions src/server/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import GraphQLJSON from 'graphql-type-json';
import { parseResolveInfo } from 'graphql-parse-resolve-info';
import _ from 'lodash';
import log from './logger';
import { firstLetterUpperCase, buildNestedFieldMapping } from './utils/utils';
import { buildNestedFieldMapping, filterFieldMapping, firstLetterUpperCase } from './utils/utils';
import { esFieldNumericTextTypeMapping, NumericTextTypeTypeEnum } from './es/const';

/**
Expand Down Expand Up @@ -236,9 +236,13 @@ const getResolver = (esConfig, esInstance) => {

const mappingResolvers = esConfig.indices.reduce((acc, cfg) => {
log.debug(`${cfg.index} `, esInstance.getESFields(cfg.index));
acc[cfg.type] = () => (_.flattenDeep(
esInstance.getESFields(cfg.index).fields.map((f) => buildNestedFieldMapping(f)),
));
acc[cfg.type] = filterFieldMapping(
_.flattenDeep(
esInstance.getESFields(cfg.index).fields.map(
(f) => buildNestedFieldMapping(f),
),
),
);
return acc;
}, {});

Expand Down
4 changes: 3 additions & 1 deletion src/server/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ export const getAggregationSchemaForEachNestedType = (esConfig, esInstance) => e

export const getMappingSchema = (esConfig) => `
type Mapping {
${esConfig.indices.map((cfg) => `${cfg.type}: [String]`).join('\n')}
${esConfig.indices.map((cfg) => `${cfg.type} (
searchInput: String
): [String]`).join('\n')}
}
`;

Expand Down
9 changes: 9 additions & 0 deletions src/server/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import config from '../config';
import log from '../logger';

export const firstLetterUpperCase = (str) => str.charAt(0).toUpperCase() + str.slice(1);

Expand Down Expand Up @@ -129,3 +130,11 @@ export const buildNestedFieldMapping = (field, parent) => {
));
return resultArray;
};

export const filterFieldMapping = (fieldArray) => (parent, args) => {
const { searchInput } = args;
const regEx = new RegExp(searchInput);
log.debug('utils [filterFieldMapping] searchInput', searchInput);
const resultArray = fieldArray.filter((field) => regEx.test(field));
return resultArray;
};