How to use the graphql.isNonNullType 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 aerogear / graphback / packages / graphql-migrations / src / abstract / generateAbstractDatabase.ts View on Github external
console.warn(`Couldn't create foreign field ${foreignKey} on type ${fieldType.name} on field ${field.name}. See above messages.`)
        return null
      }
      type = descriptor.type
      args = descriptor.args
      foreign = {
        type: foreignType.name,
        field: foreignField.name,
        tableName: null,
        columnName: null,
      }

      // List
    } else if (isListType(fieldType) && this.currentTable) {
      let ofType = fieldType.ofType
      ofType = isNonNullType(ofType) ? ofType.ofType : ofType
      if (isObjectType(ofType)) {
        // Foreign Type
        const onSameType = this.currentType === ofType.name
        const foreignType = this.typeMap[ofType.name]
        if (!foreignType) {
          console.warn(`Foreign type ${ofType.name} not found on field ${this.currentType}.${field.name}.`)
          return null
        }
        if (!isObjectType(foreignType)) {
          console.warn(`Foreign type ${ofType.name} is not Object type on field ${this.currentType}.${field.name}.`)
          return null
        }

        // Foreign Field
        const foreignKey = onSameType ? field.name : annotations.manyToMany || this.currentTable.name
        const foreignField = foreignType.getFields()[foreignKey]
github aerogear / graphback / packages / graphql-migrations / src / abstract / generateAbstractDatabase.ts View on Github external
private getFieldDescriptor(
    field: GraphQLField,
    fieldType: GraphQLOutputType | null = null,
  ): TableColumn | null {
    const annotations: any = parseAnnotations('db', field.description || null)

    if (annotations.skip) {
      return null
    }

    if (!fieldType) {
      fieldType = isNonNullType(field.type) ? field.type.ofType : field.type
    }

    const notNull = isNonNullType(field.type)
    let columnName: string = annotations.name || this.getColumnName(field.name)
    let type: string
    let args: any[]
    let foreign: ForeignKey | null = null

    if (columnName === 'id' && (isScalarType(fieldType) && fieldType.name !== 'ID')) {
      throw new Error(`Scalar ID is missing on type ${this.currentType}.${field.name}`);
    }

    // Scalar
    if (isScalarType(fieldType) || annotations.type) {
      let descriptor
      if (this.scalarMap) {
        descriptor = this.scalarMap(field, isScalarType(fieldType) ? fieldType : null, annotations)
      }
      if (!descriptor) {
github bearbytes / apollo-hooks-codegen / src / transform.ts View on Github external
function unwrap(
        type: GraphQLOutputType,
        nullable: boolean
      ): GraphQLOutputType {
        if (isNonNullType(type)) {
          return unwrap(type.ofType, false)
        }

        if (nullable) {
          addModifier('Nullable')
        }

        if (isListType(type)) {
          addModifier('ReadonlyArray')
          return unwrap(type.ofType, true)
        }

        if (isScalarType(type) || isEnumType(type) || isObjectType(type))
          return type

        throw 'unhandled GraphQLOutputType in unwrap'
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 Soluto / graphql-to-mongodb / examples / apollo / src / SolutionA / makeExecutableSchema.ts View on Github external
function innerType(type: GraphQLInputType): GraphQLInputType & GraphQLNamedType {
    if (isNonNullType(type) || isListType(type)) {
        return innerType(type.ofType);
    }
    return type;
}
github Shopify / graphql-tools-web / packages / graphql-validate-fixtures / src / validate.ts View on Github external
function validateValueAgainstType(
  value: any,
  type: GraphQLType,
  keyPath: KeyPath,
  options: TypeValidationOptions = {shallow: false},
): Error[] {
  const {shallow} = options;

  if (isNonNullType(type)) {
    return value == null
      ? [error(keyPath, `should be non-null but was ${String(value)}`)]
      : validateValueAgainstType(value, type.ofType, keyPath, options);
  }

  if (value === null) {
    return [];
  }

  const valueType = typeof value;

  if (isListType(type)) {
    if (!Array.isArray(value)) {
      return [
        error(
          keyPath,
github AEB-labs / cruddl / src / schema-generation / query-node-object-type / utils.ts View on Github external
export function isListTypeIgnoringNonNull(type: QueryNodeOutputType): boolean {
    if (isNonNullType(type) || type instanceof QueryNodeNonNullType) {
        return isListTypeIgnoringNonNull(type.ofType);
    }
    return isListType(type) || type instanceof QueryNodeListType;
}
github apollographql / apollo-tooling / packages / apollo-codegen-scala / src / naming.ts View on Github external
export function propertyFromInputField(
  context: LegacyCompilerContext,
  field: GraphQLInputField,
  namespace?: string,
  parentTraitName?: string
): GraphQLInputField & Property {
  const name = field.name;
  const unescapedPropertyName = isMetaFieldName(name) ? name : camelCase(name);
  const propertyName = escapeIdentifierIfNeeded(unescapedPropertyName);

  const type = field.type;
  const isList = isListType(type);
  const isOptional = !isNonNullType(type);
  const bareType = getNamedType(type);

  const bareTypeName = isCompositeType(bareType)
    ? join(
        [
          namespace,
          parentTraitName,
          escapeIdentifierIfNeeded(pascalCase(Inflector.singularize(name)))
        ],
        "."
      )
    : undefined;
  const typeName = typeNameFromGraphQLType(
    context,
    type,
    bareTypeName,
github OneGraph / graphiql-explorer / src / Explorer.js View on Github external
function isRequiredArgument(arg: GraphQLArgument): boolean %checks {
  return isNonNullType(arg.type) && arg.defaultValue === undefined;
}
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;
            }
        }
    }