How to use the graphql-transformer-common.isNonNullType function in graphql-transformer-common

To help you get started, we’ve selected a few graphql-transformer-common 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 / graphql-key-transformer / src / KeyTransformer.ts View on Github external
}
            }
        }
        // 3. Check that fields exists and are valid key types.
        const fieldMap = new Map();
        for (const field of definition.fields) {
            fieldMap.set(field.name.value, field);
        }
        for (const fieldName of directiveArgs.fields) {
            if (!fieldMap.has(fieldName)) {
                const checkedKeyName = directiveArgs.name ? directiveArgs.name : "";
                throw new InvalidDirectiveError(`You cannot specify a non-existant field '${fieldName}' in @key '${checkedKeyName}' on type '${definition.name.value}'.`);
            } else {
                const existingField = fieldMap.get(fieldName);
                const ddbKeyType = attributeTypeFromType(existingField.type, ctx);
                if (this.isPrimaryKey(directive) && !isNonNullType(existingField.type)) {
                    throw new InvalidDirectiveError(`The primary @key on type '${definition.name.value}' must reference non-null fields.`);
                } else if (ddbKeyType !== 'S' && ddbKeyType !== 'N' && ddbKeyType !== 'B') {
                    throw new InvalidDirectiveError(`A @key on type '${definition.name.value}' cannot reference non-scalar field ${fieldName}.`);
                }
            }
        }
    }
github aws-amplify / amplify-cli / packages / graphql-relation-transformer / src / ModelRelationTransformer.ts View on Github external
function validateKeyField(field: FieldDefinitionNode): void {
    if (!field) {
        return
    }
    const isNonNull = isNonNullType(field.type);
    const isAList = isListType(field.type)

    // The only valid key fields are single non-null fields.
    if (!isAList && isNonNull) {
        return;
    }
    throw new InvalidDirectiveError(`All fields used for a relation cannot be lists and must be of Non-Null types.`)
}
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / ModelConnectionTransformer.ts View on Github external
function validateKeyFieldNewConnection(field: FieldDefinitionNode): void {
    if (!field) {
        return
    }
    const isNonNull = isNonNullType(field.type);
    const isAList = isListType(field.type)

    // The only valid key fields are single non-null fields.
    if (!isAList && isNonNull) {
        return;
    }
    throw new InvalidDirectiveError(`All fields used for a connection cannot be lists and must be of Non-Null types.`)
}
github aws-amplify / amplify-cli / packages / graphql-transformers-e2e-tests / src / testUtil.ts View on Github external
export function expectNonNullFields(type: ObjectTypeDefinitionNode, fields: string[]) {
  for (const fieldName of fields) {
    const foundField = type.fields.find((f: FieldDefinitionNode) => f.name.value === fieldName);
    expect(foundField).toBeDefined();
    expect(isNonNullType(foundField.type)).toBeTruthy();
  }
}
github aws-amplify / amplify-cli / packages / graphql-transformers-e2e-tests / src / testUtil.ts View on Github external
export function expectNullableFields(type: ObjectTypeDefinitionNode, fields: string[]) {
  for (const fieldName of fields) {
    const foundField = type.fields.find((f: FieldDefinitionNode) => f.name.value === fieldName);
    expect(foundField).toBeDefined();
    expect(isNonNullType(foundField.type)).toBeFalsy();
  }
}
github aws-amplify / amplify-cli / packages / graphql-transformers-e2e-tests / src / testUtil.ts View on Github external
export function expectNullableInputValues(type: InputObjectTypeDefinitionNode, fields: string[]) {
  for (const fieldName of fields) {
    const foundField = type.fields.find((f: InputValueDefinitionNode) => f.name.value === fieldName);
    expect(foundField).toBeDefined();
    expect(isNonNullType(foundField.type)).toBeFalsy();
  }
}
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / ModelConnectionTransformer.ts View on Github external
return true
                    }
                }
                return false
            }
        )

        if (connectionName && !associatedConnectionField) {
            throw new InvalidDirectiveError(
                `Found one half of connection "${connectionName}" at ${parentTypeName}.${fieldName} but no related field on type ${relatedTypeName}`
            )
        }

        connectionName = connectionName || `${parentTypeName}.${fieldName}`
        const leftConnectionIsList = isListType(field.type)
        const leftConnectionIsNonNull = isNonNullType(field.type)
        const rightConnectionIsList = associatedConnectionField ? isListType(associatedConnectionField.type) : undefined
        const rightConnectionIsNonNull = associatedConnectionField ? isNonNullType(associatedConnectionField.type) : undefined

        let connectionAttributeName = getDirectiveArgument(directive)("keyField")
        const associatedSortField = associatedSortFieldName &&
            parent.fields.find((f: FieldDefinitionNode) => f.name.value === associatedSortFieldName)

        if (associatedSortField) {
            if (isListType(associatedSortField.type)) {
                throw new InvalidDirectiveError(
                    `sortField "${associatedSortFieldName}" is a list. It should be a scalar.`
                )
            }
            sortType = getBaseType(associatedSortField.type)
            if (!isScalar(associatedSortField.type) || sortType === STANDARD_SCALARS.Boolean) {
                throw new InvalidDirectiveError(
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / ModelConnectionTransformer.ts View on Github external
}
                return false
            }
        )

        if (connectionName && !associatedConnectionField) {
            throw new InvalidDirectiveError(
                `Found one half of connection "${connectionName}" at ${parentTypeName}.${fieldName} but no related field on type ${relatedTypeName}`
            )
        }

        connectionName = connectionName || `${parentTypeName}.${fieldName}`
        const leftConnectionIsList = isListType(field.type)
        const leftConnectionIsNonNull = isNonNullType(field.type)
        const rightConnectionIsList = associatedConnectionField ? isListType(associatedConnectionField.type) : undefined
        const rightConnectionIsNonNull = associatedConnectionField ? isNonNullType(associatedConnectionField.type) : undefined

        let connectionAttributeName = getDirectiveArgument(directive)("keyField")
        const associatedSortField = associatedSortFieldName &&
            parent.fields.find((f: FieldDefinitionNode) => f.name.value === associatedSortFieldName)

        if (associatedSortField) {
            if (isListType(associatedSortField.type)) {
                throw new InvalidDirectiveError(
                    `sortField "${associatedSortFieldName}" is a list. It should be a scalar.`
                )
            }
            sortType = getBaseType(associatedSortField.type)
            if (!isScalar(associatedSortField.type) || sortType === STANDARD_SCALARS.Boolean) {
                throw new InvalidDirectiveError(
                    `sortField "${associatedSortFieldName}" is of type "${sortType}". ` +
                    `It should be a scalar that maps to a DynamoDB "String", "Number", or "Binary"`