import { s } from "./forEachState.es-wKNS2oZk.js";
import { K as getNamedType, ab as GraphQLInputObjectType, ac as getNullableType, ad as GraphQLList, a0 as GraphQLEnumType, S as SchemaMetaFieldDef, P as TypeMetaFieldDef, Q as TypeNameMetaFieldDef, R as isCompositeType } from "./index-Cr4zbAtA.js";
var b = Object.defineProperty;
var r = (n, l) => b(n, "name", { value: l, configurable: true });
function E(n, l) {
  const e = {
    schema: n,
    type: null,
    parentType: null,
    inputType: null,
    directiveDef: null,
    fieldDef: null,
    argDef: null,
    argDefs: null,
    objectFieldDefs: null
  };
  return s(l, (i) => {
    var a, p;
    switch (i.kind) {
      case "Query":
      case "ShortQuery":
        e.type = n.getQueryType();
        break;
      case "Mutation":
        e.type = n.getMutationType();
        break;
      case "Subscription":
        e.type = n.getSubscriptionType();
        break;
      case "InlineFragment":
      case "FragmentDefinition":
        i.type && (e.type = n.getType(i.type));
        break;
      case "Field":
      case "AliasedField":
        e.fieldDef = e.type && i.name ? T(n, e.parentType, i.name) : null, e.type = (a = e.fieldDef) === null || a === void 0 ? void 0 : a.type;
        break;
      case "SelectionSet":
        e.parentType = e.type ? getNamedType(e.type) : null;
        break;
      case "Directive":
        e.directiveDef = i.name ? n.getDirective(i.name) : null;
        break;
      case "Arguments":
        const f = i.prevState ? i.prevState.kind === "Field" ? e.fieldDef : i.prevState.kind === "Directive" ? e.directiveDef : i.prevState.kind === "AliasedField" ? i.prevState.name && T(n, e.parentType, i.prevState.name) : null : null;
        e.argDefs = f ? f.args : null;
        break;
      case "Argument":
        if (e.argDef = null, e.argDefs) {
          for (let t = 0; t < e.argDefs.length; t++)
            if (e.argDefs[t].name === i.name) {
              e.argDef = e.argDefs[t];
              break;
            }
        }
        e.inputType = (p = e.argDef) === null || p === void 0 ? void 0 : p.type;
        break;
      case "EnumValue":
        const d = e.inputType ? getNamedType(e.inputType) : null;
        e.enumValue = d instanceof GraphQLEnumType ? Q(d.getValues(), (t) => t.value === i.name) : null;
        break;
      case "ListValue":
        const g = e.inputType ? getNullableType(e.inputType) : null;
        e.inputType = g instanceof GraphQLList ? g.ofType : null;
        break;
      case "ObjectValue":
        const s2 = e.inputType ? getNamedType(e.inputType) : null;
        e.objectFieldDefs = s2 instanceof GraphQLInputObjectType ? s2.getFields() : null;
        break;
      case "ObjectField":
        const c = i.name && e.objectFieldDefs ? e.objectFieldDefs[i.name] : null;
        e.inputType = c == null ? void 0 : c.type;
        break;
      case "NamedType":
        e.type = i.name ? n.getType(i.name) : null;
        break;
    }
  }), e;
}
r(E, "getTypeInfo");
function T(n, l, e) {
  if (e === SchemaMetaFieldDef.name && n.getQueryType() === l)
    return SchemaMetaFieldDef;
  if (e === TypeMetaFieldDef.name && n.getQueryType() === l)
    return TypeMetaFieldDef;
  if (e === TypeNameMetaFieldDef.name && isCompositeType(l))
    return TypeNameMetaFieldDef;
  if (l && l.getFields)
    return l.getFields()[e];
}
r(T, "getFieldDef");
function Q(n, l) {
  for (let e = 0; e < n.length; e++)
    if (l(n[e]))
      return n[e];
}
r(Q, "find");
function L(n) {
  return {
    kind: "Field",
    schema: n.schema,
    field: n.fieldDef,
    type: o(n.fieldDef) ? null : n.parentType
  };
}
r(L, "getFieldReference");
function R(n) {
  return {
    kind: "Directive",
    schema: n.schema,
    directive: n.directiveDef
  };
}
r(R, "getDirectiveReference");
function _(n) {
  return n.directiveDef ? {
    kind: "Argument",
    schema: n.schema,
    argument: n.argDef,
    directive: n.directiveDef
  } : {
    kind: "Argument",
    schema: n.schema,
    argument: n.argDef,
    field: n.fieldDef,
    type: o(n.fieldDef) ? null : n.parentType
  };
}
r(_, "getArgumentReference");
function G(n) {
  return {
    kind: "EnumValue",
    value: n.enumValue || void 0,
    type: n.inputType ? getNamedType(n.inputType) : void 0
  };
}
r(G, "getEnumValueReference");
function O(n, l) {
  return {
    kind: "Type",
    schema: n.schema,
    type: l || n.type
  };
}
r(O, "getTypeReference");
function o(n) {
  return n.name.slice(0, 2) === "__";
}
r(o, "isMetaField");
export {
  E,
  G,
  L,
  O,
  R,
  _
};
