import { newInvariantError } from "@apollo/client/utilities/invariant";
import { checkDocument } from "./checkDocument.js";
/**
* 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.
*/
export function getMainDefinition(queryDoc) {
    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 newInvariantError(12);
}
//# sourceMappingURL=getMainDefinition.js.map
