import { c as create_ssr_component, h as subscribe, v as validate_component, f as escape } from "../../../_app/immutable/chunks/index-27250121.js";
import { isObjectType } from "graphql";
import { w as writable, n as getTypeByName, f as findPageByHref } from "../../../_app/immutable/chunks/pages-a57618e2.js";
import { A as AnchorHeader, b as CodeSpan, a as Prism_1, P as PreviousNextPage } from "../../../_app/immutable/chunks/PreviousNextPage-aa1b7b9e.js";
import "../../../_app/immutable/chunks/prism-json-f6ca42ec.js";
import { C as ContentSwitcher, S as Switch } from "../../../_app/immutable/chunks/Switch-303c7246.js";
import { MissingCustomScalarException } from "@magidoc/plugin-query-generator";
import "lodash";
import { O as ObjectType } from "../../../_app/immutable/chunks/ObjectType-ef80b091.js";
import "@magidoc/plugin-starter-variables";
import "../../../_app/immutable/chunks/paths-b9644fda.js";
import "@magidoc/plugin-reverse-schema-mapper";
import "../../../_app/immutable/chunks/ArgsList-5cf1bc5a.js";
const currentCode = writable();
const generateQuery = ({
  type
}) => {
  try {
    return {
      jsCode: `client
  .upsertNodes('${type.name}', [
    {
      externalId: '${type.name}-1',
      // any additional properties (missing required property will throw error)
    },
  ])
  .then((res) => {
    console.log(res);
  });
`,
      pythonCode: ""
    };
  } catch (error) {
    if (error instanceof MissingCustomScalarException) {
      throw new Error(`
Cannot generate a random value for scalar '${error.type.name}'. 
The random generator is not able to randomly generate a value for non-standard GraphQL scalars. 
You have to provide a custom factory by providing this in your magidoc config:
{
  website: {
    options: {
      queryGenerationFactories: {
        '${error.type.name}': '<an-example-of-scalar-value>'
      }
    }
  }
}

To learn more about how to generate a custom scalar value, see: https://magidoc-org.github.io/magidoc/cli/magidoc-configuration#querygenerationfactories
`);
    }
    throw error;
  }
};
const upsertCode = {
  subscribe: currentCode.subscribe,
  setField: (type) => currentCode.update(
    (current) => generateQuery({
      type
    })
  )
};
const UpsertDetails_svelte_svelte_type_style_lang = "";
const css = {
  code: ".wrapper.svelte-1xxaho6{display:flex}.content.svelte-1xxaho6{flex:1}.sample.svelte-1xxaho6{width:700px}",
  map: null
};
const UpsertDetails = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let $upsertCode, $$unsubscribe_upsertCode;
  $$unsubscribe_upsertCode = subscribe(upsertCode, (value) => $upsertCode = value);
  let { type } = $$props;
  let selectedTab = 0;
  if ($$props.type === void 0 && $$bindings.type && type !== void 0)
    $$bindings.type(type);
  $$result.css.add(css);
  let $$settled;
  let $$rendered;
  do {
    $$settled = true;
    {
      {
        upsertCode.setField(type);
      }
    }
    $$rendered = `<section>${validate_component(AnchorHeader, "AnchorHeader").$$render($$result, { id: "title", depth: 1 }, {}, {
      default: () => {
        return `Upsert - ${escape(type.name)}`;
      }
    })}

  <div class="${"wrapper svelte-1xxaho6"}"><div class="${"content svelte-1xxaho6"}">${validate_component(ObjectType, "ObjectType").$$render($$result, { type }, {}, {})}</div>
    <div class="${"sample svelte-1xxaho6"}">${validate_component(ContentSwitcher, "ContentSwitcher").$$render(
      $$result,
      { selectedIndex: selectedTab },
      {
        selectedIndex: ($$value) => {
          selectedTab = $$value;
          $$settled = false;
        }
      },
      {
        default: () => {
          return `${validate_component(Switch, "Switch").$$render($$result, { text: "JS (Autogenerated SDK)" }, {}, {})}
        ${validate_component(Switch, "Switch").$$render($$result, { text: "Python (Autogenerated SDK)" }, {}, {})}`;
        }
      }
    )}
      <div>${selectedTab === 0 ? `${validate_component(AnchorHeader, "AnchorHeader").$$render($$result, { id: "installing", depth: 4 }, {}, {
      default: () => {
        return `Setting up the SDK`;
      }
    })}
          <p style="${"margin-bottom:12px"}">To use queries in JavaScript / TypeScript directly in your code,
            make sure you have already built the <a href="${"/getting-started#javascript--typescript-autogenerated-sdk"}">Autogenerated JS SDK via the CLI</a></p>
          ${validate_component(AnchorHeader, "AnchorHeader").$$render($$result, { id: "installing", depth: 4 }, {}, {
      default: () => {
        return `Running the query`;
      }
    })}
          <p style="${"margin-bottom:12px"}">In the below code, we assume the ${validate_component(CodeSpan, "CodeSpan").$$render($$result, {}, {}, {
      default: () => {
        return `client`;
      }
    })}
            is already authenticated instance of ${validate_component(CodeSpan, "CodeSpan").$$render($$result, {}, {}, {
      default: () => {
        return `FDMQueryClient`;
      }
    })}
            .
          </p>
          <p style="${"margin-bottom:12px"}">As well, the code below assumes that you have already imported ${validate_component(CodeSpan, "CodeSpan").$$render($$result, {}, {}, {
      default: () => {
        return `everything`;
      }
    })}. This is a built in functionality to help you fetch all immediate
            &quot;scalar&quot; values (non-nested values). Hence feel free to adjust the
            &quot;depth&quot; on the right hand side to see how nested values looks.
          </p>
          ${validate_component(Prism_1, "Prism").$$render(
      $$result,
      {
        maxHeight: "20rem",
        minHeight: "12rem",
        source: $upsertCode.jsCode ?? "# No query generated. Try increasing the depth",
        language: "typescript"
      },
      {},
      {}
    )}` : ``}
        ${selectedTab === 1 ? `${validate_component(AnchorHeader, "AnchorHeader").$$render($$result, { id: "installing", depth: 4 }, {}, {
      default: () => {
        return `Setting up the SDK`;
      }
    })}
          <p style="${"margin-bottom:12px"}">To use queries in Python directly in your code, make sure you have
            already built the <a href="${"/getting-started#python-autogenerated-sdk"}">Autogenerated Python SDK via the CLI</a></p>
          ${validate_component(AnchorHeader, "AnchorHeader").$$render($$result, { id: "installing", depth: 4 }, {}, {
      default: () => {
        return `Running the query`;
      }
    })}
          <p style="${"margin-bottom:12px"}">In the below code, we assume the ${validate_component(CodeSpan, "CodeSpan").$$render($$result, {}, {}, {
      default: () => {
        return `client`;
      }
    })}
            is already authenticated instance of ${validate_component(CodeSpan, "CodeSpan").$$render($$result, {}, {}, {
      default: () => {
        return `FDMQueryClient`;
      }
    })}
            .
          </p>
          ${validate_component(Prism_1, "Prism").$$render(
      $$result,
      {
        maxHeight: "20rem",
        minHeight: "12rem",
        source: $upsertCode.pythonCode ?? "# No query generated. Try increasing the depth",
        language: "typescript"
      },
      {},
      {}
    )}` : ``}</div></div></div>
</section>`;
  } while (!$$settled);
  $$unsubscribe_upsertCode();
  return $$rendered;
});
function load({ params, url }) {
  const type = getTypeByName(params.type);
  const page = findPageByHref(url.pathname);
  if (!type || !page) {
    return {
      status: 404,
      error: `Type ${params.type} not found.`
    };
  }
  return { props: { type, page } };
}
const U5Btypeu5D = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let { type } = $$props;
  let { usages } = $$props;
  let { page } = $$props;
  if ($$props.type === void 0 && $$bindings.type && type !== void 0)
    $$bindings.type(type);
  if ($$props.usages === void 0 && $$bindings.usages && usages !== void 0)
    $$bindings.usages(usages);
  if ($$props.page === void 0 && $$bindings.page && page !== void 0)
    $$bindings.page(page);
  return `${$$result.head += `${$$result.title = `<title>Upsert - ${escape(type.name)}</title>`, ""}`, ""}

${isObjectType(type) ? `${validate_component(UpsertDetails, "UpsertDetails").$$render($$result, { type }, {}, {})}` : ``}

${validate_component(PreviousNextPage, "PreviousNextPage").$$render($$result, { page }, {}, {})}`;
});
export {
  U5Btypeu5D as default,
  load
};
