How to use the graphql-compose.isObject function in graphql-compose

To help you get started, we’ve selected a few graphql-compose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphql-compose / graphql-compose-elasticsearch / src / mappingConverter.js View on Github external
// 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]) {
github graphql-compose / graphql-compose-elasticsearch / src / mappingConverter.js View on Github external
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],
github graphql-compose / graphql-compose-mongoose / src / utils / toMongoDottedObject.js View on Github external
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,
        };
github graphql-compose / graphql-compose-elasticsearch / src / resolvers / search.js View on Github external
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;