import { t as require_graphql } from "./graphql-DskHmkMe.mjs";
import { n as initialSchemaStr, r as typeDefsDoc, t as hiddenQueryTypeDefDoc } from "./documents-BFBPmyw1.mjs";
import { createContext, useContext, useMemo } from "react";
import { jsx } from "react/jsx-runtime";
//#region editors/document-model-editor/context/schema-context.tsx
var import_graphql = require_graphql();
const hiddenQueryTypeDefinitions = safeParseSdl(hiddenQueryTypeDefDoc)?.definitions ?? [];
const standardLibCustomScalarDefinitions = safeParseSdl(typeDefsDoc)?.definitions ?? [];
const alwaysIncludedDefinitions = [...hiddenQueryTypeDefinitions, ...standardLibCustomScalarDefinitions];
function makeSharedSchemaSdl(globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl) {
	const definitions = [...alwaysIncludedDefinitions];
	for (const sdl of [
		globalStateSchemaSdl,
		localStateSchemaSdl,
		operationSchemasSdl
	]) {
		if (!sdl) continue;
		const ast = safeParseSdl(sdl);
		if (!ast) continue;
		definitions.push(...ast.definitions);
	}
	return (0, import_graphql.printSchema)((0, import_graphql.buildASTSchema)({
		kind: import_graphql.Kind.DOCUMENT,
		definitions
	}));
}
function safeParseSdl(sdl) {
	try {
		if (!sdl) return null;
		return (0, import_graphql.parse)(sdl);
	} catch (_error) {
		return null;
	}
}
const SchemaContext = createContext({
	sharedSchema: initialSchemaStr,
	error: void 0
});
function parseSharedSchemaSdl(globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl) {
	try {
		return {
			sharedSchema: makeSharedSchemaSdl(globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl),
			error: void 0
		};
	} catch (error) {
		return {
			sharedSchema: initialSchemaStr,
			error: error instanceof Error ? error : new Error(typeof error === "string" ? error : JSON.stringify(error), { cause: error })
		};
	}
}
function SchemaContextProvider(props) {
	const { children, globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl } = props;
	const sharedSchemaSdl = useMemo(() => parseSharedSchemaSdl(globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl), [
		globalStateSchemaSdl,
		localStateSchemaSdl,
		operationSchemasSdl
	]);
	return /* @__PURE__ */ jsx(SchemaContext.Provider, {
		value: sharedSchemaSdl,
		children
	});
}
function useSchemaContext() {
	return useContext(SchemaContext);
}
//#endregion
export { safeParseSdl as n, useSchemaContext as r, SchemaContextProvider as t };

//# sourceMappingURL=schema-context-CX5ml_9t.mjs.map