"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMainDefinition = getMainDefinition;
const invariant_1 = require("@apollo/client/utilities/invariant");
const checkDocument_js_1 = require("./checkDocument.cjs");
/**
* Returns the first operation definition found in this document.
* If no operation definition is found, the first fragment definition will be returned.
* If no definitions are found, an error will be thrown.
*
* @internal
* 
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
*/
function getMainDefinition(queryDoc) {
    (0, checkDocument_js_1.checkDocument)(queryDoc);
    let fragmentDefinition;
    for (let definition of queryDoc.definitions) {
        if (definition.kind === "OperationDefinition") {
            return definition;
        }
        if (definition.kind === "FragmentDefinition" && !fragmentDefinition) {
            // we do this because we want to allow multiple fragment definitions
            // to precede an operation definition.
            fragmentDefinition = definition;
        }
    }
    if (fragmentDefinition) {
        return fragmentDefinition;
    }
    throw (0, invariant_1.newInvariantError)(12);
}
//# sourceMappingURL=getMainDefinition.cjs.map
