@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
JavaScript
import { An as e, Cn as t, Ct as n, Et as r, Ft as i, H as a, Lt as o, Mt as s, Pt as c, Rt as l, V as u, X as d, a as f, r as p, tt as m, vn as h, wt as g } from "./monaco-editor-DTNTBWG9.js";
import { f as _, h as v, p as y } from "./editor.api-HRp2tMTX.js";
// ../../../node_modules/.pnpm/graphql@17.1.0/node_modules/graphql/utilities/printSchema.mjs
function b(e) {
return S(e, (e) => !d(e), x);
}
function x(e) {
return !m(e) && !u(e);
}
function S(e, t, n) {
let r = e.getDirectives().filter(t), i = Object.values(e.getTypeMap()).filter(n);
return [
C(e),
...r.map((e) => F(e)),
...i.map((e) => T(e))
].filter(Boolean).join("\n\n");
}
function C(e) {
let t = e.getQueryType(), n = e.getMutationType(), r = e.getSubscriptionType();
if ((t || n || r) && (e.description != null || !w(e))) return R(e) + "schema {\n" + (t ? ` query: ${t}\n` : "") + (n ? ` mutation: ${n}\n` : "") + (r ? ` subscription: ${r}\n` : "") + "}";
}
function w(e) {
return e.getQueryType() == e.getType("Query") && e.getMutationType() == e.getType("Mutation") && e.getSubscriptionType() == e.getType("Subscription");
}
function T(a) {
if (c(a)) return E(a);
if (s(a)) return ee(a);
if (r(a)) return te(a);
if (i(a)) return O(a);
if (n(a)) return k(a);
if (g(a)) return A(a);
t(!1, "Unexpected type: " + e(a));
}
function E(e) {
return R(e) + `scalar ${e}` + L(e);
}
function D(e) {
let t = e.getInterfaces();
return t.length ? " implements " + t.map((e) => e.name).join(" & ") : "";
}
function ee(e) {
return R(e) + `type ${e}` + D(e) + j(e);
}
function te(e) {
return R(e) + `interface ${e}` + D(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 = a(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: h,
value: e
})})`;
}
function L(e) {
return e.specifiedByURL == null ? "" : ` @specifiedBy(url: ${o({
kind: h,
value: e.specifiedByURL
})})`;
}
function R(e, t = "", n = !0) {
let { description: r } = e;
if (r == null) return "";
let i = o({
kind: h,
value: r,
block: l(r)
});
return (t && !n ? "\n" + t : t) + i.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: b(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 = f(n, o.buildSchemaOptions);
return {
...o,
documentString: b(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 = y.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) => {
y.setModelMarkers(e, this.defaults.languageId, []);
let t = e.uri.toString(), n = this._listener[t];
n && (n.dispose(), delete this._listener[t]);
};
this._disposables.push(y.onDidCreateModel(r), { dispose() {
clearTimeout(n);
} }, y.onWillDisposeModel((e) => {
i(e);
}), y.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 y.getModels()) z(e) === this.defaults.languageId && (i(e), r(e));
}));
for (let e of y.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 (y.setModelMarkers(y.getModel(e), t, i), n) {
if (await import("./monaco.contribution-Cv0Nmq69.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 = _.file(n[0].replace(".json", "-schema.json")).toString(), a = {
uri: i,
schema: t,
fileMatch: n
}, o = v.json.jsonDefaults.diagnosticsOptions.schemas?.filter((e) => e.uri !== i) || [];
v.json.jsonDefaults.setDiagnosticsOptions({
schemaValidation: "error",
validate: !0,
...this.defaults.diagnosticSettings.jsonDiagnosticSettings,
schemas: [...o, a],
enableSchemaRequest: !1
});
}
}
}, W = v.CompletionItemKind, G = {
[p.Text]: W.Text,
[p.Method]: W.Method,
[p.Function]: W.Function,
[p.Constructor]: W.Constructor,
[p.Field]: W.Field,
[p.Variable]: W.Variable,
[p.Class]: W.Class,
[p.Interface]: W.Interface,
[p.Module]: W.Module,
[p.Property]: W.Property,
[p.Unit]: W.Unit,
[p.Value]: W.Value,
[p.Enum]: W.Enum,
[p.Keyword]: W.Keyword,
[p.Snippet]: W.Snippet,
[p.Color]: W.Color,
[p.File]: W.File,
[p.Reference]: W.Reference,
[p.Folder]: W.Folder,
[p.EnumMember]: W.EnumMember,
[p.Constant]: W.Constant,
[p.Struct]: W.Struct,
[p.Event]: W.Event,
[p.Operator]: W.Operator,
[p.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 ? v.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(v.registerDocumentFormattingEditProvider(r, new Y(i)));
}
function o(t) {
let { modeConfiguration: r, languageId: o } = e;
$(n), r.completionItems && n.push(v.registerCompletionItemProvider(o, new J(i))), r.diagnostics && n.push(new U(t, i)), r.hovers && n.push(v.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 };