Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// mapping
const { properties } = ((prop: any): ElasticMappingT);
if (properties && isObject(properties)) {
Object.keys(properties).forEach(subFieldName => {
inputPropertiesToGraphQLTypes(
properties[subFieldName],
[fieldName, subFieldName].filter(o => !!o).join('__'),
result
);
});
return result;
}
// object type with subfields
const { fields } = ((prop: any): ElasticPropertyT);
if (fields && isObject(fields)) {
Object.keys(fields).forEach(subFieldName => {
inputPropertiesToGraphQLTypes(
fields[subFieldName],
[fieldName, subFieldName].filter(o => !!o).join('__'),
result
);
});
}
// skip no index fields
if ({}.hasOwnProperty.call(prop, 'index') && !prop.index) {
return result;
}
if (typeof prop.type === 'string' && fieldName) {
if (!result[prop.type]) {
export function inputPropertiesToGraphQLTypes(
prop: ElasticPropertyT | ElasticMappingT,
fieldName?: string,
result?: FieldsMapByElasticType = { _all: {} }
): FieldsMapByElasticType {
if (!prop || (typeof prop.type !== 'string' && !prop.properties)) {
throw new Error('You provide incorrect Elastic property config.');
}
// mapping
const { properties } = ((prop: any): ElasticMappingT);
if (properties && isObject(properties)) {
Object.keys(properties).forEach(subFieldName => {
inputPropertiesToGraphQLTypes(
properties[subFieldName],
[fieldName, subFieldName].filter(o => !!o).join('__'),
result
);
});
return result;
}
// object type with subfields
const { fields } = ((prop: any): ElasticPropertyT);
if (fields && isObject(fields)) {
Object.keys(fields).forEach(subFieldName => {
inputPropertiesToGraphQLTypes(
fields[subFieldName],
function _toMongoDottedObject(obj, target = {}, path = [], filter = false) {
if (!isObject(obj) && !Array.isArray(obj)) return obj;
if (isPrimitive(obj)) return obj;
const objKeys = Object.keys(obj);
/* eslint-disable */
objKeys.forEach(key => {
if (key.startsWith('$')) {
const val = Array.isArray(obj[key])
? obj[key].map(v => _toMongoDottedObject(v, {}, [], filter))
: _toMongoDottedObject(obj[key], {}, [], filter);
if (path.length === 0) {
target[key] = val;
} else {
target[path.join('.')] = {
...target[path.join('.')],
[key]: val,
};
Object.keys(projection).forEach(k => {
if (isObject(projection[k])) {
const tmp = toDottedList(projection[k], prev ? [...prev, k] : [k]);
if (Array.isArray(tmp)) {
result = result.concat(tmp);
return;
}
}
if (prev) {
result.push([...prev, k].join('.'));
} else {
result.push(k);
}
});
return result.length > 0 ? result : true;