"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var graphql_1 = require("graphql");
function safeChangeForField(oldType, newType) {
    if (!graphql_1.isWrappingType(oldType) && !graphql_1.isWrappingType(newType)) {
        return oldType === newType;
    }
    if (graphql_1.isNonNullType(newType)) {
        var ofType = graphql_1.isNonNullType(oldType) ? oldType.ofType : oldType;
        return safeChangeForField(ofType, newType.ofType);
    }
    if (graphql_1.isListType(oldType)) {
        return ((graphql_1.isListType(newType) &&
            safeChangeForField(oldType.ofType, newType.ofType)) ||
            (graphql_1.isNonNullType(newType) && safeChangeForField(oldType, newType.ofType)));
    }
    return false;
}
exports.safeChangeForField = safeChangeForField;
function safeChangeForInputValue(oldType, newType) {
    if (!graphql_1.isWrappingType(oldType) && !graphql_1.isWrappingType(newType)) {
        return oldType === newType;
    }
    if (graphql_1.isListType(oldType) && graphql_1.isListType(newType)) {
        return safeChangeForInputValue(oldType.ofType, newType.ofType);
    }
    if (graphql_1.isNonNullType(oldType)) {
        var ofType = graphql_1.isNonNullType(newType) ? newType : newType;
        return safeChangeForInputValue(oldType.ofType, ofType);
    }
    return false;
}
exports.safeChangeForInputValue = safeChangeForInputValue;
function getTypePrefix(type) {
    var _a;
    var kind = type.astNode.kind;
    var kindsMap = (_a = {},
        _a[graphql_1.Kind.SCALAR_TYPE_DEFINITION] = 'scalar',
        _a[graphql_1.Kind.OBJECT_TYPE_DEFINITION] = 'type',
        _a[graphql_1.Kind.INTERFACE_TYPE_DEFINITION] = 'interface',
        _a[graphql_1.Kind.UNION_TYPE_DEFINITION] = 'union',
        _a[graphql_1.Kind.ENUM_TYPE_DEFINITION] = 'enum',
        _a[graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION] = 'input',
        _a);
    return kindsMap[kind];
}
exports.getTypePrefix = getTypePrefix;
function isPrimitive(type) {
    return (['String', 'Int', 'Float', 'Boolean', 'ID'].indexOf(typeof type === 'string' ? type : type.name) !== -1);
}
exports.isPrimitive = isPrimitive;
function isForIntrospection(type) {
    return ([
        '__Schema',
        '__Type',
        '__TypeKind',
        '__Field',
        '__InputValue',
        '__EnumValue',
        '__Directive',
        '__DirectiveLocation',
    ].indexOf(typeof type === 'string' ? type : type.name) !== -1);
}
exports.isForIntrospection = isForIntrospection;
//# sourceMappingURL=graphql.js.map