UNPKG

@graphql-hive/laboratory

Version:

[Hive](https://the-guild.dev/graphql/hive) is a fully open-source schema registry, analytics, metrics and gateway for [GraphQL federation](https://the-guild.dev/graphql/hive/federation) and other GraphQL APIs.

358 lines (357 loc) • 11.2 kB
import { At as e, Bt as t, Cn as n, Dt as r, Fn as i, H as a, Ht as o, It as s, On as c, Ot as l, U as u, Ut as d, Z as f, a as p, it as m, r as h, zt as ee } from "./monaco-editor-BzSKoqsB.js"; import { f as g, h as _, p as v } from "./editor.api-DX-lPANk.js"; // ../../../node_modules/.pnpm/graphql@17.1.0/node_modules/graphql/utilities/printSchema.mjs function y(e) { return x(e, (e) => !f(e), b); } function b(e) { return !m(e) && !a(e); } function x(e, t, n) { let r = e.getDirectives().filter(t), i = Object.values(e.getTypeMap()).filter(n); return [ S(e), ...r.map((e) => F(e)), ...i.map((e) => w(e)) ].filter(Boolean).join("\n\n"); } function S(e) { let t = e.getQueryType(), n = e.getMutationType(), r = e.getSubscriptionType(); if ((t || n || r) && (e.description != null || !C(e))) return R(e) + "schema {\n" + (t ? ` query: ${t}\n` : "") + (n ? ` mutation: ${n}\n` : "") + (r ? ` subscription: ${r}\n` : "") + "}"; } function C(e) { return e.getQueryType() == e.getType("Query") && e.getMutationType() == e.getType("Mutation") && e.getSubscriptionType() == e.getType("Subscription"); } function w(n) { if (ee(n)) return T(n); if (s(n)) return te(n); if (e(n)) return D(n); if (t(n)) return O(n); if (r(n)) return k(n); if (l(n)) return A(n); c(!1, "Unexpected type: " + i(n)); } function T(e) { return R(e) + `scalar ${e}` + L(e); } function E(e) { let t = e.getInterfaces(); return t.length ? " implements " + t.map((e) => e.name).join(" & ") : ""; } function te(e) { return R(e) + `type ${e}` + E(e) + j(e); } function D(e) { return R(e) + `interface ${e}` + E(e) + j(e); } function O(e) { let t = e.getTypes(), n = t.length ? " = " + t.join(" | ") : ""; return R(e) + `union ${e.name}` + n; } function k(e) { let t = e.getValues().map((e, t) => R(e, " ", !t) + " " + e.name + I(e.deprecationReason)); return R(e) + `enum ${e}` + M(t); } function A(e) { let t = Object.values(e.getFields()).map((e, t) => R(e, " ", !t) + " " + P(e)); return R(e) + `input ${e}` + (e.isOneOf ? " @oneOf" : "") + M(t); } function j(e) { return M(Object.values(e.getFields()).map((e, t) => R(e, " ", !t) + " " + e.name + N(e.args, " ") + ": " + String(e.type) + I(e.deprecationReason))); } function M(e) { return e.length === 0 ? "" : " {\n" + e.join("\n") + "\n}"; } function N(e, t = "") { return e.length === 0 ? "" : e.every((e) => e.description == null) ? "(" + e.map(P).join(", ") + ")" : "(\n" + e.map((e, n) => R(e, " " + t, !n) + " " + t + P(e)).join("\n") + "\n" + t + ")"; } function P(e) { let t = e.name + ": " + String(e.type), n = u(e); return n && (t += ` = ${o(n)}`), t + I(e.deprecationReason); } function F(e) { return R(e) + `directive ${e}` + N(e.args) + I(e.deprecationReason) + (e.isRepeatable ? " repeatable" : "") + " on " + e.locations.join(" | "); } function I(e) { return e == null ? "" : e === "No longer supported" ? " @deprecated" : ` @deprecated(reason: ${o({ kind: n, value: e })})`; } function L(e) { return e.specifiedByURL == null ? "" : ` @specifiedBy(url: ${o({ kind: n, value: e.specifiedByURL })})`; } function R(e, t = "", r = !0) { let { description: i } = e; if (i == null) return ""; let a = o({ kind: n, value: i, block: d(i) }); return (t && !r ? "\n" + t : t) + a.replaceAll("\n", "\n" + t) + "\n"; } // ../../../node_modules/.pnpm/monaco-graphql@1.9.0_graphql@17.1.0_monaco-editor@0.52.2_prettier@3.4.2/node_modules/monaco-graphql/esm/utils.js var z = (e) => "getModeId" in e ? e.getModeId() : e.getLanguageId(), B = (e) => { let { schema: t, documentAST: n, introspectionJSON: r, introspectionJSONString: i, documentString: a, ...o } = e; if (t) return { ...o, documentString: y(t) }; if (i) return { ...o, introspectionJSONString: i }; if (a) return { ...o, documentString: a }; if (r) return { ...o, introspectionJSONString: JSON.stringify(r) }; if (n) { let e = p(n, o.buildSchemaOptions); return { ...o, documentString: y(e) }; } throw Error("No schema supplied"); }, V = 12e4, H = class { _defaults; _idleCheckInterval; _lastUsedTime = 0; _configChangeListener; _worker = null; _client = null; constructor(e) { this._defaults = e, this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 3e4), this._configChangeListener = this._defaults.onDidChange(() => { this._stopWorker(); }); } _stopWorker() { this._worker &&= (this._worker.dispose(), null), this._client = null; } dispose() { clearInterval(this._idleCheckInterval), this._configChangeListener.dispose(), this._stopWorker(); } _checkIfIdle() { this._worker && Date.now() - this._lastUsedTime > V && this._stopWorker(); } async _getClient() { if (this._lastUsedTime = Date.now(), !this._client && !this._worker) try { let { languageId: e, formattingOptions: t, schemas: n, externalFragmentDefinitions: r, completionSettings: i, experimentalFragmentArguments: a } = this._defaults; this._worker = v.createWebWorker({ moduleId: "monaco-graphql/esm/GraphQLWorker.js", label: e, createData: { languageId: e, formattingOptions: t, languageConfig: { schemas: n?.map(B), externalFragmentDefinitions: r, experimentalFragmentArguments: a, fillLeafsOnComplete: i.__experimental__fillLeafsOnComplete } } }), this._client = this._worker.getProxy(); } catch (e) { console.error("error loading worker", e); } return this._client; } async getLanguageServiceWorker(...e) { let t = await this._getClient(); return await this._worker.withSyncedResources(e), t; } }, U = class { defaults; _worker; _disposables = []; _listener = Object.create(null); constructor(e, t) { this.defaults = e, this._worker = t, this._worker = t; let n, r = (t) => { let r = z(t); if (r !== this.defaults.languageId) return; let i = t.uri.toString(), a = e.diagnosticSettings.validateVariablesJSON?.[i]; n = setTimeout(() => { this._doValidate(t.uri, r, a); }, 400), this._listener[i] = t.onDidChangeContent(() => { clearTimeout(n), n = setTimeout(() => { this._doValidate(t.uri, r, a); }, 400); }); }, i = (e) => { v.setModelMarkers(e, this.defaults.languageId, []); let t = e.uri.toString(), n = this._listener[t]; n && (n.dispose(), delete this._listener[t]); }; this._disposables.push(v.onDidCreateModel(r), { dispose() { clearTimeout(n); } }, v.onWillDisposeModel((e) => { i(e); }), v.onDidChangeModelLanguage((e) => { i(e.model), r(e.model); }), { dispose: () => { for (let e of Object.values(this._listener)) e.dispose(); } }, e.onDidChange(() => { for (let e of v.getModels()) z(e) === this.defaults.languageId && (i(e), r(e)); })); for (let e of v.getModels()) z(e) === this.defaults.languageId && r(e); } dispose() { for (let e of this._disposables) e.dispose(); this._disposables = []; } async _doValidate(e, t, n) { let r = await this._worker(e); if (!r) return; let i = await r.doValidation(e.toString()); if (v.setModelMarkers(v.getModel(e), t, i), n) { if (await import("./monaco.contribution-Bw1EXBxx.js").then((e) => e.t), !n.length) throw Error("No variables URI strings provided to validate"); let t = await r.doGetVariablesJSONSchema(e.toString()); if (!t) return; let i = g.file(n[0].replace(".json", "-schema.json")).toString(), a = { uri: i, schema: t, fileMatch: n }, o = _.json.jsonDefaults.diagnosticsOptions.schemas?.filter((e) => e.uri !== i) || []; _.json.jsonDefaults.setDiagnosticsOptions({ schemaValidation: "error", validate: !0, ...this.defaults.diagnosticSettings.jsonDiagnosticSettings, schemas: [...o, a], enableSchemaRequest: !1 }); } } }, W = _.CompletionItemKind, G = { [h.Text]: W.Text, [h.Method]: W.Method, [h.Function]: W.Function, [h.Constructor]: W.Constructor, [h.Field]: W.Field, [h.Variable]: W.Variable, [h.Class]: W.Class, [h.Interface]: W.Interface, [h.Module]: W.Module, [h.Property]: W.Property, [h.Unit]: W.Unit, [h.Value]: W.Value, [h.Enum]: W.Enum, [h.Keyword]: W.Keyword, [h.Snippet]: W.Snippet, [h.Color]: W.Color, [h.File]: W.File, [h.Reference]: W.Reference, [h.Folder]: W.Folder, [h.EnumMember]: W.EnumMember, [h.Constant]: W.Constant, [h.Struct]: W.Struct, [h.Event]: W.Event, [h.Operator]: W.Operator, [h.TypeParameter]: W.TypeParameter }; function K(e) { return e in G ? G[e] : W.Text; } function q(e) { return { range: e.range, kind: K(e.kind), label: e.label, insertText: e.insertText ?? e.label, insertTextRules: e.insertText ? _.CompletionItemInsertTextRule.InsertAsSnippet : void 0, sortText: e.sortText, filterText: e.filterText, documentation: e.documentation, detail: e.detail, command: e.command }; } var J = class { _worker; constructor(e) { this._worker = e, this._worker = e; } get triggerCharacters() { return [ ":", "$", " ", "(", "@" ]; } async provideCompletionItems(e, t, n, r) { try { return { incomplete: !0, suggestions: (await (await this._worker(e.uri)).doComplete(e.uri.toString(), t)).map(q) }; } catch (e) { return console.error("Error fetching completion items", e), { suggestions: [] }; } } }, Y = class { _worker; constructor(e) { this._worker = e, this._worker = e; } async provideDocumentFormattingEdits(e, t, n) { let r = await (await this._worker(e.uri)).doFormat(e.uri.toString()); return r ? [{ range: e.getFullModelRange(), text: r }] : []; } }, X = class { _worker; constructor(e) { this._worker = e; } async provideHover(e, t, n) { let r = e.uri, i = await (await this._worker(e.uri)).doHover(r.toString(), t); return i ? { range: i.range, contents: [{ value: i.content }] } : { contents: [] }; } dispose() {} }; // ../../../node_modules/.pnpm/monaco-graphql@1.9.0_graphql@17.1.0_monaco-editor@0.52.2_prettier@3.4.2/node_modules/monaco-graphql/esm/graphqlMode.js function Z(e) { let t = [], n = [], r = new H(e); t.push(r); let i = (...e) => { try { return r.getLanguageServiceWorker(...e); } catch { throw Error("Error fetching graphql language service worker"); } }; function a() { let { modeConfiguration: t, languageId: r } = e; t.documentFormattingEdits && n.push(_.registerDocumentFormattingEditProvider(r, new Y(i))); } function o(t) { let { modeConfiguration: r, languageId: o } = e; $(n), r.completionItems && n.push(_.registerCompletionItemProvider(o, new J(i))), r.diagnostics && n.push(new U(t, i)), r.hovers && n.push(_.registerHoverProvider(o, new X(i))), a(); } let { modeConfiguration: s, formattingOptions: c, diagnosticSettings: l, externalFragmentDefinitions: u, schemas: d } = e; return o(e), e.onDidChange((e) => { e.modeConfiguration !== s && (s = e.modeConfiguration, o(e)), e.formattingOptions !== c && (c = e.formattingOptions, a()), e.externalFragmentDefinitions !== u && (u = e.externalFragmentDefinitions, o(e)), e.diagnosticSettings !== l && (l = e.diagnosticSettings, o(e)), e.schemas !== d && (d = e.schemas, o(e)); }), t.push(Q(n)), Q(t); } function Q(e) { return { dispose: () => $(e) }; } function $(e) { for (; e.length;) e.pop().dispose(); } export { Z as setupMode };