How to use the iterall.isCollection function in iterall

To help you get started, we’ve selected a few iterall 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-factory / graphql-factory / src / execution / request.js View on Github external
function completeListValue(
  exeContext: ExecutionContext,
  returnType: GraphQLList<*>,
  fieldNodes: Array,
  info: GraphQLResolveInfo,
  path: ResponsePath,
  result: mixed
): mixed {
  invariant(
    isCollection(result),
    `Expected Iterable, but did not find one for field ${
      info.parentType.name}.${info.fieldName}.`
  );

  // This is specified as a simple map, however we're optimizing the path
  // where the list contains no Promises by avoiding creating another Promise.
  const itemType = returnType.ofType;
  let containsPromise = false;
  const completedResults = [];
  forEach((result: any), (item, index) => {
    // No need to modify the info object containing the path,
    // since from here on it is not ever accessed by resolver functions.
    const fieldPath = addPath(path, index);
    const completedItem = completeValueCatchingError(
      exeContext,
      itemType,
github apollographql / apollo-server / packages / apollo-server-defer / src / execute.ts View on Github external
function completeListValue(
  exeContext: ExecutionContext,
  returnType: GraphQLList,
  fieldNodes: ReadonlyArray,
  info: GraphQLResolveInfo,
  path: ResponsePath,
  result: {},
): MaybePromise> {
  invariant(
    isCollection(result),
    `Expected Iterable, but did not find one for field ${
      info.parentType.name
    }.${info.fieldName}.`,
  );

  // This is specified as a simple map, however we're optimizing the path
  // where the list contains no Promises by avoiding creating another Promise.
  const itemType = returnType.ofType;
  let containsPromise = false;
  const completedResults = [];
  forEach(result as any, (item, index) => {
    // No need to modify the info object containing the path,
    // since from here on it is not ever accessed by resolver functions.
    const fieldPath = addPath(path, index);
    const completedItem = completeValueCatchingError(
      exeContext,
github graphql / graphql-js / src / execution / execute.js View on Github external
function completeListValue(
  exeContext: ExecutionContext,
  returnType: GraphQLList,
  fieldNodes: $ReadOnlyArray,
  info: GraphQLResolveInfo,
  path: Path,
  result: mixed,
): PromiseOrValue<$ReadOnlyArray> {
  if (!isCollection(result)) {
    throw new GraphQLError(
      `Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
    );
  }

  // This is specified as a simple map, however we're optimizing the path
  // where the list contains no Promises by avoiding creating another Promise.
  const itemType = returnType.ofType;
  let containsPromise = false;
  const completedResults = [];
  forEach((result: any), (item, index) => {
    // No need to modify the info object containing the path,
    // since from here on it is not ever accessed by resolver functions.
    const fieldPath = addPath(path, index);
    const completedItem = completeValueCatchingError(
      exeContext,
github graphql / graphql-js / module / execution / execute.js View on Github external
function completeListValue(exeContext, returnType, fieldNodes, info, path, result) {
  !isCollection(result) ? invariant(0, 'Expected Iterable, but did not find one for field ' + info.parentType.name + '.' + info.fieldName + '.') : void 0;

  // This is specified as a simple map, however we're optimizing the path
  // where the list contains no Promises by avoiding creating another Promise.
  var itemType = returnType.ofType;
  var containsPromise = false;
  var completedResults = [];
  forEach(result, function (item, index) {
    // No need to modify the info object containing the path,
    // since from here on it is not ever accessed by resolver functions.
    var fieldPath = addPath(path, index);
    var completedItem = completeValueCatchingError(exeContext, itemType, fieldNodes, info, fieldPath, item);

    if (!containsPromise && getPromise(completedItem)) {
      containsPromise = true;
    }
    completedResults.push(completedItem);
github graphql / graphql-js / src / execution / values.js View on Github external
if (type instanceof GraphQLNonNull) {
    if (_value === null) {
      return; // Intentionally return no value.
    }
    return coerceValue(type.ofType, _value);
  }

  if (_value === null) {
    // Intentionally return the value null.
    return null;
  }

  if (type instanceof GraphQLList) {
    const itemType = type.ofType;
    if (isCollection(_value)) {
      const coercedValues = [];
      const valueIter = createIterator((_value: any));
      if (!valueIter) {
        return; // Intentionally return no value.
      }
      let step;
      while (!(step = valueIter.next()).done) {
        const itemValue = coerceValue(itemType, step.value);
        if (isInvalid(itemValue)) {
          return; // Intentionally return no value.
        }
        coercedValues.push(itemValue);
      }
      return coercedValues;
    }
    const coercedValue = coerceValue(itemType, _value);
github leebyron / react-loops / react-loops.js View on Github external
if ((props.hasOwnProperty("of") ^ hasIn) === 0) {
    throw new TypeError(
      " expects either a Collection `of` or Object `in` prop."
    );
  }

  if (hasIn) {
    // Get the object
    var obj = props.in;

    // Accept null / falsey as nothing to loop.
    if (!obj) {
      return renderEmpty(props);
    }

    if (iterall.isCollection(obj) || typeof obj !== "object") {
      throw new TypeError(
        " expects a non-collection Object. " +
          "Perhaps you meant to use  with a Collection?"
      );
    }

    // Get the set of keys, rendering as empty if there are no keys.
    var keys = Object.keys(obj);
    var length = keys.length;
    if (length === 0) {
      return renderEmpty(props);
    }

    // Map each object property key into a React child.
    var mapped = [];
    for (var i = 0; i < length; i++) {
github facebook / relay / packages / relay-test-utils / RelayModernTestUtils.js View on Github external
function check(value) {
        expect(Object.isFrozen(value)).toBe(true);
        if (isCollection(value)) {
          forEach(value, check);
        } else if (typeof value === 'object' && value !== null) {
          for (const key in value) {
            check(value[key]);
          }
        }
      }
      check(actual);