plugins/ant-graphql/functions/resolve.js
async function resolve (ant, resolveArgs, fieldArgs, currentValue, model) {
  let field = null;
  if (model) {
    field = model.field;
  }
  if (ant && resolveArgs && resolveArgs.to) {
    const antFunction =  ant.functionController.getFunction(resolveArgs.to);
    if (!antFunction) {
      logger.error(new AntError(
        `Could not find "${resolveArgs.to}" function`
      ));
      return null;
    }
    try {
      currentValue = antFunction.run(
        currentValue !== undefined ? currentValue : fieldArgs
      );
      if (currentValue instanceof Observable) {
        if (
          field &&
          field.astNode &&
          field.astNode.type &&
          field.astNode.type.kind === 'ListType'
        ) {
          return await currentValue.pipe(
            flatMap(data => data instanceof Array ? data : [ data ]),
            toArray()
          ).toPromise();
        } else {
          return await currentValue.toPromise();
        }
      } else {
        return currentValue;
      }
    } catch (e) {
      logger.error(new AntError(
        `Could not run "${resolveArgs.to}" function`,
        e
      ));
    }
  }
  return null;
}
async function resolve (ant, resolveArgs, fieldArgs, currentValue, model) {
  let field = null;
  if (model) {
    field = model.field;
  }
  if (ant && resolveArgs && resolveArgs.to) {
    const antFunction =  ant.functionController.getFunction(resolveArgs.to);
    if (!antFunction) {
      logger.error(new AntError(
        `Could not find "${resolveArgs.to}" function`
      ));
      return null;
    }
    try {
      currentValue = antFunction.run(
        currentValue !== undefined ? currentValue : fieldArgs
      );
      if (currentValue instanceof Observable) {
        if (
          field &&
          field.astNode &&
          field.astNode.type &&
          field.astNode.type.kind === 'ListType'
        ) {
          return await currentValue.pipe(
            flatMap(data => data instanceof Array ? data : [ data ]),
            toArray()
          ).toPromise();
        } else {
          return await currentValue.toPromise();
        }
      } else {
        return currentValue;
      }
    } catch (e) {
      logger.error(new AntError(
        `Could not run "${resolveArgs.to}" function`,
        e
      ));
    }
  }
  return null;
}
async function resolve ( ant , resolveArgs , fieldArgs , currentValue , model ) { let field = null ; if ( model ) { field = model . field ; } if ( ant && resolveArgs && resolveArgs . to ) { const antFunction = ant . functionController . getFunction ( resolveArgs . to ) ; if ( ! antFunction ) { logger . error ( new AntError ( ` ${ resolveArgs . to } ` ) ) ; return null ; } try { currentValue = antFunction . run ( currentValue !== undefined ? currentValue : fieldArgs ) ; if ( currentValue instanceof Observable ) { if ( field && field . astNode && field . astNode . type && field . astNode . type . kind === 'ListType' ) { return await currentValue . pipe ( flatMap ( data => data instanceof Array ? data : [ data ] ) , toArray ( ) ) . toPromise ( ) ; } else { return await currentValue . toPromise ( ) ; } } else { return currentValue ; } } catch ( e ) { logger . error ( new AntError ( ` ${ resolveArgs . to } ` , e ) ) ; } } return null ; }
This function resolves a GraphQL field value.
This function resolves a GraphQL field value .