How to use the graphql.isListType function in graphql

To help you get started, we’ve selected a few graphql 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 aws-amplify / amplify-cli / packages / amplify-graphql-docs-generator / src / generator / utils / isRequired.ts View on Github external
export default function isRequired(typeObj: GraphQLType): boolean {
  if (isNonNullType(typeObj) && isListType(typeObj.ofType)) {
    // See if it's a Non-null List of Non-null Types
    return isRequired(typeObj.ofType.ofType);
  }
  if (isListType(typeObj)) {
    // See if it's a Nullable List of Non-null Types
    return isNonNullType(typeObj.ofType);
  }
  return isNonNullType(typeObj);
}
github dotansimha / graphql-code-generator / packages / plugins / java / apollo-android / src / operation-visitor.ts View on Github external
const childInlineFragments: { onType: string; node: InlineFragmentNode }[] = [];
    const childFragmentSpread: LoadedFragment[] = [...(options.additionalFragments || [])];

    const selections = [...(options.selectionSet || [])];
    const responseFieldArr: string[] = [];

    for (const selection of selections) {
      if (selection.kind === Kind.FIELD) {
        this._imports.add(Imports.ResponseField);
        const field = fields[selection.name.value];
        const isObject = selection.selectionSet && selection.selectionSet.selections && selection.selectionSet.selections.length > 0;
        const isNonNull = isNonNullType(field.type);
        const fieldAnnotation = isNonNull ? 'Nonnull' : 'Nullable';
        this._imports.add(Imports[fieldAnnotation]);
        const baseType = getBaseType(field.type);
        const isList = isListType(field.type) || (isNonNullType(field.type) && isListType(field.type.ofType));

        if (isObject) {
          let childClsName = this.convertName(field.name);

          if (isList && isPlural(childClsName)) {
            childClsName = singular(childClsName);
          }

          this.transformSelectionSet(
            {
              className: childClsName,
              result: options.result,
              selectionSet: selection.selectionSet.selections,
              schemaType: baseType as GraphQLObjectType,
            },
            false
github genie-team / graphql-genie / lib / TypeGeneratorUtils.js View on Github external
export const typeIsList = (type) => {
    let isList = false;
    if (type.name && type.name.endsWith('Connection')) {
        isList = true;
    }
    while (!isList && (isListType(type) || isNonNullType(type) || type.kind === 'NON_NULL' || type.kind === 'LIST')) {
        if (isListType(type) || type.kind === 'LIST') {
            isList = true;
            break;
        }
        type = type.ofType;
    }
    return isList;
};
export const getReturnType = (type) => {
github genie-team / graphql-genie / lib / TypeGeneratorUtils.js View on Github external
export const generateFieldsForInput = (fieldName, inputTypes, defaultValue) => {
    const fields = {};
    fields[fieldName] = {
        type: inputTypes[0],
        defaultValue: defaultValue
    };
    if (inputTypes[1] && !isScalarType(getReturnGraphQLType(inputTypes[0]))) {
        const idName = isListType(inputTypes[1]) ? fieldName + 'Ids' : fieldName + 'Id';
        fields[idName] = {
            type: inputTypes[1]
        };
    }
    return fields;
};
export const stripNonNull = (type) => {
github Urigo / SOFA / src / open-api / types.ts View on Github external
export function resolveFieldType(
  type: GraphQLOutputType | GraphQLNamedType
): any {
  if (isNonNullType(type)) {
    return resolveFieldType(type.ofType);
  }

  if (isListType(type)) {
    return {
      type: 'array',
      items: resolveFieldType(type.ofType),
    };
  }

  if (isObjectType(type)) {
    return {
      $ref: mapToRef(type.name),
    };
  }

  if (isScalarType(type)) {
    return (
      mapToPrimitive(type.name) || {
        type: 'object',
github kamilkisiela / graphql-inspector / packages / core / src / utils / graphql.ts View on Github external
export function safeChangeForInputValue(
  oldType: GraphQLInputType,
  newType: GraphQLInputType,
): boolean {
  if (!isWrappingType(oldType) && !isWrappingType(newType)) {
    return oldType.toString() === newType.toString();
  }

  if (isListType(oldType) && isListType(newType)) {
    return safeChangeForInputValue(oldType.ofType, newType.ofType);
  }

  if (isNonNullType(oldType)) {
    const ofType = isNonNullType(newType) ? newType : newType;

    return safeChangeForInputValue(oldType.ofType, ofType);
  }

  return false;
}
github bearbytes / apollo-hooks-codegen / dist / index.js View on Github external
function handleInputType(node) {
            if (graphql_1.isNonNullType(node)) {
                handleInputType(node.ofType);
                return;
            }
            if (graphql_1.isListType(node)) {
                handleInputType(node.ofType);
                return;
            }
            if (graphql_1.isInputObjectType(node)) {
                if (!inputTypeNames[node.name]) {
                    inputTypeNames[node.name] = true;
                    newNames2.push(node.name);
                }
                return;
            }
        }
    }
github apollographql / apollo-tooling / packages / apollo-codegen-typescript / src / helpers.ts View on Github external
function nonNullableTypeFromGraphQLType(
    graphQLType: GraphQLType,
    typeName?: string
  ): t.TSType {
    if (isListType(graphQLType)) {
      const elementType = typeFromGraphQLType(graphQLType.ofType, typeName);
      return ArrayType(
        t.isTSUnionType(elementType)
          ? t.TSParenthesizedType(elementType)
          : elementType
      );
    } else if (isScalarType(graphQLType)) {
      const builtIn = builtInScalarMap[typeName || graphQLType.name];
      if (builtIn != null) {
        return builtIn;
      } else if (compilerOptions.passthroughCustomScalars) {
        return t.TSTypeReference(
          t.identifier(
            (compilerOptions.customScalarsPrefix || "") + graphQLType.name
          )
        );
github Shopify / quilt / packages / jest-mock-apollo / src / MockApolloLink.ts View on Github external
function rootType(type: GraphQLType) {
  let finalType = type;

  while (isNonNullType(finalType) || isListType(finalType)) {
    finalType = finalType.ofType;
  }

  return finalType;
}