import { c as Kind, t as parse } from "./parser-CkF6Qt8V.js";
import { n as initialSchemaStr, o as printSchema, r as typeDefsDoc, s as buildASTSchema, t as hiddenQueryTypeDefDoc } from "./documents-D4ek7Ubv.js";
import { createContext, useContext, useMemo } from "react";
import { jsx } from "react/jsx-runtime";
//#region editors/document-model-editor/context/schema-context.tsx
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 printSchema(buildASTSchema({
		kind: Kind.DOCUMENT,
		definitions
	}));
}
function safeParseSdl(sdl) {
	try {
		if (!sdl) return null;
		return 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-DY-GEGnY.js.map