@parhelia/alpaca 0.4.13049 → 0.4.13170
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/GraphQL.d.ts +2 -0
- package/dist/GraphQL.d.ts.map +1 -0
- package/dist/GraphQL.js +200 -0
- package/dist/GraphiQLPanel.d.ts +15 -0
- package/dist/GraphiQLPanel.d.ts.map +1 -0
- package/dist/GraphiQLPanel.js +207 -0
- package/dist/Layout.d.ts +2 -0
- package/dist/Layout.d.ts.map +1 -0
- package/dist/Layout.js +67 -0
- package/dist/componentCommands.js +2 -6
- package/dist/graphqlService.d.ts +77 -0
- package/dist/graphqlService.d.ts.map +1 -0
- package/dist/graphqlService.js +518 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -4
- package/dist/services.d.ts +3 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +10 -0
- package/dist/tracing/components/TracingTitlebar.d.ts.map +1 -1
- package/dist/tracing/components/TracingTitlebar.js +7 -13
- package/package.json +5 -1
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
import { get, post } from "@parhelia/core";
|
|
2
|
+
import { buildClientSchema, getIntrospectionQuery, Kind, parse, print, visit, } from "graphql";
|
|
3
|
+
const GRAPHQL_V2_QUERY_URL = "/alpaca/headless/graphql/v2/query";
|
|
4
|
+
const GRAPHQL_V1_QUERY_URL = "/alpaca/headless/graphql";
|
|
5
|
+
const GRAPHQL_V1_SCHEMA_URL = "/alpaca/headless/graphql/schema";
|
|
6
|
+
const V2_TO_V1_FALLBACK_STATUSES = new Set([
|
|
7
|
+
400, 404, 405, 415, 500, 501, 502, 503, 504,
|
|
8
|
+
]);
|
|
9
|
+
const DEFAULT_INTROSPECTION_QUERY = getIntrospectionQuery({
|
|
10
|
+
descriptions: true,
|
|
11
|
+
schemaDescription: true,
|
|
12
|
+
directiveIsRepeatable: true,
|
|
13
|
+
});
|
|
14
|
+
export const INTROSPECTION_QUERY = DEFAULT_INTROSPECTION_QUERY;
|
|
15
|
+
function shouldFallbackToV1(status) {
|
|
16
|
+
return V2_TO_V1_FALLBACK_STATUSES.has(status);
|
|
17
|
+
}
|
|
18
|
+
export function isSchemaIntrospectionQuery(query) {
|
|
19
|
+
return /\b__(schema|type)\b/.test(query);
|
|
20
|
+
}
|
|
21
|
+
export function createExplicitItemArgs(item) {
|
|
22
|
+
return `id: "${item.id}", language: "${item.language}", version: ${item.version}`;
|
|
23
|
+
}
|
|
24
|
+
function createExplicitItemArgumentNodes(item) {
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
kind: Kind.ARGUMENT,
|
|
28
|
+
name: { kind: Kind.NAME, value: "id" },
|
|
29
|
+
value: { kind: Kind.STRING, value: item.id },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
kind: Kind.ARGUMENT,
|
|
33
|
+
name: { kind: Kind.NAME, value: "language" },
|
|
34
|
+
value: { kind: Kind.STRING, value: item.language },
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
kind: Kind.ARGUMENT,
|
|
38
|
+
name: { kind: Kind.NAME, value: "version" },
|
|
39
|
+
value: { kind: Kind.INT, value: String(item.version) },
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
export function createStarterQuery(item) {
|
|
44
|
+
return `query CurrentItem {
|
|
45
|
+
item(${createExplicitItemArgs(item)}) {
|
|
46
|
+
id
|
|
47
|
+
name
|
|
48
|
+
path
|
|
49
|
+
}
|
|
50
|
+
}`;
|
|
51
|
+
}
|
|
52
|
+
function hasExplicitItemSelector(query) {
|
|
53
|
+
return /item\s*\((?=[^)]*\bid\s*:)(?=[^)]*\blanguage\s*:)(?=[^)]*\bversion\s*:)[^)]*\)/i.test(query);
|
|
54
|
+
}
|
|
55
|
+
function rewriteContextShortcutItems(query, item) {
|
|
56
|
+
let rewritten = false;
|
|
57
|
+
const explicitArgs = createExplicitItemArgs(item);
|
|
58
|
+
const rewrittenQuery = query.replace(/item\s*\(([^)]*)\)/gi, (match, args) => {
|
|
59
|
+
if (/path\s*:\s*["']__[^"']+["']/i.test(args)) {
|
|
60
|
+
rewritten = true;
|
|
61
|
+
return `item(${explicitArgs})`;
|
|
62
|
+
}
|
|
63
|
+
return match;
|
|
64
|
+
});
|
|
65
|
+
return { rewrittenQuery, rewritten };
|
|
66
|
+
}
|
|
67
|
+
function rewriteImplicitItemSelections(query, item) {
|
|
68
|
+
try {
|
|
69
|
+
let rewritten = false;
|
|
70
|
+
const parsed = parse(query);
|
|
71
|
+
const explicitArgs = createExplicitItemArgumentNodes(item);
|
|
72
|
+
const rewrittenDocument = visit(parsed, {
|
|
73
|
+
Field(node, _key, parent, _path, ancestors) {
|
|
74
|
+
if (node.name.value !== "item" ||
|
|
75
|
+
(node.arguments?.length ?? 0) > 0 ||
|
|
76
|
+
!node.selectionSet) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const parentNode = ancestors[ancestors.length - 1];
|
|
80
|
+
const inOperationSelectionSet = parentNode &&
|
|
81
|
+
typeof parentNode === "object" &&
|
|
82
|
+
"kind" in parentNode &&
|
|
83
|
+
parentNode.kind === Kind.SELECTION_SET &&
|
|
84
|
+
ancestors.some((ancestor) => ancestor &&
|
|
85
|
+
typeof ancestor === "object" &&
|
|
86
|
+
"kind" in ancestor &&
|
|
87
|
+
ancestor.kind === Kind.OPERATION_DEFINITION);
|
|
88
|
+
if (!inOperationSelectionSet) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
rewritten = true;
|
|
92
|
+
return {
|
|
93
|
+
...node,
|
|
94
|
+
arguments: explicitArgs,
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
rewrittenQuery: print(rewrittenDocument),
|
|
100
|
+
rewritten,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return { rewrittenQuery: query, rewritten: false };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function normalizePanelQuery(query, item) {
|
|
108
|
+
if (isSchemaIntrospectionQuery(query) || hasExplicitItemSelector(query)) {
|
|
109
|
+
return { query };
|
|
110
|
+
}
|
|
111
|
+
const { rewrittenQuery, rewritten } = rewriteContextShortcutItems(query, item);
|
|
112
|
+
if (rewritten && hasExplicitItemSelector(rewrittenQuery)) {
|
|
113
|
+
return {
|
|
114
|
+
query: rewrittenQuery,
|
|
115
|
+
warning: "Query used context shortcuts and was rewritten to explicit item(id, language, version).",
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const { rewrittenQuery: implicitItemQuery, rewritten: implicitItemRewritten, } = rewriteImplicitItemSelections(query, item);
|
|
119
|
+
if (implicitItemRewritten && hasExplicitItemSelector(implicitItemQuery)) {
|
|
120
|
+
return {
|
|
121
|
+
query: implicitItemQuery,
|
|
122
|
+
warning: "Query used item without arguments and was rewritten to explicit item(id, language, version) for the selected base item.",
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (/\b__page\b/i.test(query)) {
|
|
126
|
+
return {
|
|
127
|
+
error: "Context shortcuts like __page are not allowed. Use item(id, language, version) explicitly instead.",
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return { query };
|
|
131
|
+
}
|
|
132
|
+
function getDatabaseFromMode(mode) {
|
|
133
|
+
const lowered = mode?.toLowerCase();
|
|
134
|
+
if (lowered === "edit" || lowered === "preview") {
|
|
135
|
+
return "master";
|
|
136
|
+
}
|
|
137
|
+
return "web";
|
|
138
|
+
}
|
|
139
|
+
function getStatus(result) {
|
|
140
|
+
return result.response?.status ?? 500;
|
|
141
|
+
}
|
|
142
|
+
function getErrorMessage(result) {
|
|
143
|
+
return (result.details || result.summary || result.rawDetails || "Request failed");
|
|
144
|
+
}
|
|
145
|
+
function joinWarnings(...warnings) {
|
|
146
|
+
return warnings.filter(Boolean).join(" ");
|
|
147
|
+
}
|
|
148
|
+
function parseJsonSafely(text) {
|
|
149
|
+
if (!text.trim()) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
return JSON.parse(text);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function getOperationDefinitions(document) {
|
|
160
|
+
return document.definitions.filter((definition) => definition.kind === Kind.OPERATION_DEFINITION);
|
|
161
|
+
}
|
|
162
|
+
function getSelectedOperation(document, operationName) {
|
|
163
|
+
const operations = getOperationDefinitions(document);
|
|
164
|
+
if (operationName) {
|
|
165
|
+
const matchingOperation = operations.find((operation) => operation.name?.value === operationName);
|
|
166
|
+
if (!matchingOperation) {
|
|
167
|
+
throw new Error(`Could not find operation "${operationName}" in the current document.`);
|
|
168
|
+
}
|
|
169
|
+
return matchingOperation;
|
|
170
|
+
}
|
|
171
|
+
if (operations.length !== 1) {
|
|
172
|
+
throw new Error("Alpaca GraphQL execution expects a single operation. Select exactly one operation before running the query.");
|
|
173
|
+
}
|
|
174
|
+
const selectedOperation = operations[0];
|
|
175
|
+
if (!selectedOperation) {
|
|
176
|
+
throw new Error("No GraphQL operation was found in the current document.");
|
|
177
|
+
}
|
|
178
|
+
return selectedOperation;
|
|
179
|
+
}
|
|
180
|
+
function collectReferencedFragments(definition, fragmentMap, visited = new Set()) {
|
|
181
|
+
visit(definition, {
|
|
182
|
+
FragmentSpread(node) {
|
|
183
|
+
if (visited.has(node.name.value)) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
visited.add(node.name.value);
|
|
187
|
+
const fragment = fragmentMap.get(node.name.value);
|
|
188
|
+
if (fragment) {
|
|
189
|
+
collectReferencedFragments(fragment, fragmentMap, visited);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
return visited;
|
|
194
|
+
}
|
|
195
|
+
function createValueNode(value) {
|
|
196
|
+
if (value === null) {
|
|
197
|
+
return { kind: Kind.NULL };
|
|
198
|
+
}
|
|
199
|
+
if (Array.isArray(value)) {
|
|
200
|
+
return {
|
|
201
|
+
kind: Kind.LIST,
|
|
202
|
+
values: value.map((entry) => createValueNode(entry)),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
switch (typeof value) {
|
|
206
|
+
case "boolean":
|
|
207
|
+
return { kind: Kind.BOOLEAN, value };
|
|
208
|
+
case "number":
|
|
209
|
+
if (!Number.isFinite(value)) {
|
|
210
|
+
throw new Error("Only finite numbers can be inlined into GraphQL queries.");
|
|
211
|
+
}
|
|
212
|
+
return Number.isInteger(value)
|
|
213
|
+
? { kind: Kind.INT, value: String(value) }
|
|
214
|
+
: { kind: Kind.FLOAT, value: String(value) };
|
|
215
|
+
case "string":
|
|
216
|
+
return { kind: Kind.STRING, value };
|
|
217
|
+
case "object":
|
|
218
|
+
return {
|
|
219
|
+
kind: Kind.OBJECT,
|
|
220
|
+
fields: Object.entries(value).map(([name, entry]) => ({
|
|
221
|
+
kind: Kind.OBJECT_FIELD,
|
|
222
|
+
name: { kind: Kind.NAME, value: name },
|
|
223
|
+
value: createValueNode(entry),
|
|
224
|
+
})),
|
|
225
|
+
};
|
|
226
|
+
default:
|
|
227
|
+
throw new Error(`Unsupported variable value type "${typeof value}" for GraphQL inlining.`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function compileQueryForExecution(options) {
|
|
231
|
+
try {
|
|
232
|
+
const document = parse(options.query);
|
|
233
|
+
const selectedOperation = getSelectedOperation(document, options.operationName);
|
|
234
|
+
const fragmentMap = new Map(document.definitions
|
|
235
|
+
.filter((definition) => definition.kind === Kind.FRAGMENT_DEFINITION)
|
|
236
|
+
.map((definition) => [definition.name.value, definition]));
|
|
237
|
+
const referencedFragments = collectReferencedFragments(selectedOperation, fragmentMap);
|
|
238
|
+
const reducedDocument = {
|
|
239
|
+
kind: Kind.DOCUMENT,
|
|
240
|
+
definitions: [
|
|
241
|
+
selectedOperation,
|
|
242
|
+
...Array.from(referencedFragments)
|
|
243
|
+
.map((name) => fragmentMap.get(name))
|
|
244
|
+
.filter((definition) => Boolean(definition)),
|
|
245
|
+
],
|
|
246
|
+
};
|
|
247
|
+
const variableDefinitions = selectedOperation.variableDefinitions ?? [];
|
|
248
|
+
const hasVariables = variableDefinitions.length > 0 &&
|
|
249
|
+
variableDefinitions.some((definition) => options.variables?.[definition.variable.name.value] !== undefined ||
|
|
250
|
+
definition.defaultValue !== undefined);
|
|
251
|
+
if (!hasVariables) {
|
|
252
|
+
return { ok: true, query: print(reducedDocument) };
|
|
253
|
+
}
|
|
254
|
+
const inlinedDocument = visit(reducedDocument, {
|
|
255
|
+
OperationDefinition(node) {
|
|
256
|
+
return {
|
|
257
|
+
...node,
|
|
258
|
+
variableDefinitions: [],
|
|
259
|
+
};
|
|
260
|
+
},
|
|
261
|
+
Variable(node) {
|
|
262
|
+
const definition = variableDefinitions.find((entry) => entry.variable.name.value === node.name.value);
|
|
263
|
+
if (!definition) {
|
|
264
|
+
throw new Error(`Unknown variable "${node.name.value}" in GraphQL query.`);
|
|
265
|
+
}
|
|
266
|
+
const explicitValue = options.variables?.[node.name.value];
|
|
267
|
+
if (explicitValue !== undefined) {
|
|
268
|
+
return createValueNode(explicitValue);
|
|
269
|
+
}
|
|
270
|
+
if (definition.defaultValue) {
|
|
271
|
+
return definition.defaultValue;
|
|
272
|
+
}
|
|
273
|
+
throw new Error(`Variable "$${node.name.value}" is required, but Alpaca GraphQL requests do not accept a separate variables payload.`);
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
ok: true,
|
|
278
|
+
query: print(inlinedDocument),
|
|
279
|
+
warning: "Variables were inlined client-side because the Alpaca GraphQL endpoints do not accept a separate variables payload.",
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
return {
|
|
284
|
+
ok: false,
|
|
285
|
+
error: error instanceof Error ? error.message : String(error),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
export async function executeGraphQLQuery({ query, host, path, language, mode, itemId, version, siteName, schema, sessionId, }) {
|
|
290
|
+
const modeValue = mode || "normal";
|
|
291
|
+
const v2Response = await post(GRAPHQL_V2_QUERY_URL, {
|
|
292
|
+
Query: query,
|
|
293
|
+
Schema: schema,
|
|
294
|
+
ItemContext: {
|
|
295
|
+
Database: getDatabaseFromMode(modeValue),
|
|
296
|
+
Language: language,
|
|
297
|
+
SiteName: siteName || "website",
|
|
298
|
+
ItemId: itemId,
|
|
299
|
+
Mode: modeValue,
|
|
300
|
+
},
|
|
301
|
+
}, sessionId);
|
|
302
|
+
if (v2Response.type === "success") {
|
|
303
|
+
if (v2Response.data?.errors) {
|
|
304
|
+
return {
|
|
305
|
+
status: 400,
|
|
306
|
+
errors: v2Response.data.errors,
|
|
307
|
+
transport: { requested: "v2", used: "v2" },
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
data: v2Response.data?.data,
|
|
312
|
+
status: getStatus(v2Response),
|
|
313
|
+
transport: { requested: "v2", used: "v2" },
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
const v2Status = getStatus(v2Response);
|
|
317
|
+
if (!shouldFallbackToV1(v2Status)) {
|
|
318
|
+
return {
|
|
319
|
+
status: v2Status,
|
|
320
|
+
errors: [{ message: getErrorMessage(v2Response) }],
|
|
321
|
+
transport: { requested: "v2", used: "v2" },
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const v1Response = await post(GRAPHQL_V1_QUERY_URL, {
|
|
325
|
+
Query: query,
|
|
326
|
+
Host: host,
|
|
327
|
+
Path: path,
|
|
328
|
+
ItemId: itemId,
|
|
329
|
+
Language: language,
|
|
330
|
+
Version: version,
|
|
331
|
+
Mode: mode,
|
|
332
|
+
SiteName: siteName,
|
|
333
|
+
Schema: schema,
|
|
334
|
+
}, sessionId);
|
|
335
|
+
if (v1Response.type !== "success") {
|
|
336
|
+
return {
|
|
337
|
+
status: getStatus(v1Response),
|
|
338
|
+
errors: [{ message: getErrorMessage(v1Response) }],
|
|
339
|
+
transport: {
|
|
340
|
+
requested: "v2",
|
|
341
|
+
used: "v1-fallback",
|
|
342
|
+
fallbackFromStatus: v2Status,
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
if (v1Response.data?.errors) {
|
|
347
|
+
return {
|
|
348
|
+
status: 400,
|
|
349
|
+
errors: v1Response.data.errors,
|
|
350
|
+
transport: {
|
|
351
|
+
requested: "v2",
|
|
352
|
+
used: "v1-fallback",
|
|
353
|
+
fallbackFromStatus: v2Status,
|
|
354
|
+
},
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
console.warn("GraphQL v2 request fell back to v1", JSON.stringify({
|
|
358
|
+
v2Status,
|
|
359
|
+
v1Status: getStatus(v1Response),
|
|
360
|
+
endpoint: GRAPHQL_V2_QUERY_URL,
|
|
361
|
+
}));
|
|
362
|
+
return {
|
|
363
|
+
data: v1Response.data?.data,
|
|
364
|
+
status: getStatus(v1Response),
|
|
365
|
+
transport: {
|
|
366
|
+
requested: "v2",
|
|
367
|
+
used: "v1-fallback",
|
|
368
|
+
fallbackFromStatus: v2Status,
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
export async function getGraphQLSchema({ id, language, version, mode, siteName, }) {
|
|
373
|
+
const v2Response = await executeGraphQLQuery({
|
|
374
|
+
query: DEFAULT_INTROSPECTION_QUERY,
|
|
375
|
+
itemId: id,
|
|
376
|
+
language,
|
|
377
|
+
version,
|
|
378
|
+
mode: mode || "edit",
|
|
379
|
+
siteName,
|
|
380
|
+
});
|
|
381
|
+
if (v2Response.status === 200 && !v2Response.errors) {
|
|
382
|
+
return {
|
|
383
|
+
data: JSON.stringify(v2Response.data ?? {}, null, 2),
|
|
384
|
+
status: v2Response.status,
|
|
385
|
+
transport: v2Response.transport,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
if (!shouldFallbackToV1(v2Response.status)) {
|
|
389
|
+
return {
|
|
390
|
+
status: v2Response.status,
|
|
391
|
+
error: v2Response.errors?.[0]?.message || "Schema introspection failed",
|
|
392
|
+
transport: v2Response.transport,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const v1Url = `${GRAPHQL_V1_SCHEMA_URL}?id=${encodeURIComponent(id)}`;
|
|
396
|
+
const v1Response = await get(v1Url);
|
|
397
|
+
if (v1Response.type !== "success") {
|
|
398
|
+
return {
|
|
399
|
+
status: getStatus(v1Response),
|
|
400
|
+
error: getErrorMessage(v1Response),
|
|
401
|
+
transport: {
|
|
402
|
+
requested: "v2",
|
|
403
|
+
used: "v1-fallback",
|
|
404
|
+
fallbackFromStatus: v2Response.status,
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
const schemaText = v1Response.data ?? (await v1Response.response.text());
|
|
409
|
+
console.warn("GraphQL schema request fell back to v1", JSON.stringify({
|
|
410
|
+
v2Status: v2Response.status,
|
|
411
|
+
v1Status: getStatus(v1Response),
|
|
412
|
+
endpoint: v1Url,
|
|
413
|
+
}));
|
|
414
|
+
return {
|
|
415
|
+
data: schemaText,
|
|
416
|
+
status: getStatus(v1Response),
|
|
417
|
+
transport: {
|
|
418
|
+
requested: "v2",
|
|
419
|
+
used: "v1-fallback",
|
|
420
|
+
fallbackFromStatus: v2Response.status,
|
|
421
|
+
},
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
export async function executeGraphiQLRequest(options) {
|
|
425
|
+
const compiledQuery = compileQueryForExecution({
|
|
426
|
+
query: options.query,
|
|
427
|
+
variables: options.variables,
|
|
428
|
+
operationName: options.operationName,
|
|
429
|
+
});
|
|
430
|
+
if (!compiledQuery.ok) {
|
|
431
|
+
return { status: 400, error: compiledQuery.error };
|
|
432
|
+
}
|
|
433
|
+
const normalized = normalizePanelQuery(compiledQuery.query, options.item);
|
|
434
|
+
if (normalized.error) {
|
|
435
|
+
return {
|
|
436
|
+
status: 400,
|
|
437
|
+
error: normalized.error,
|
|
438
|
+
compiledQuery: compiledQuery.query,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
const effectiveQuery = normalized.query ?? compiledQuery.query;
|
|
442
|
+
const warning = joinWarnings(normalized.warning, compiledQuery.warning);
|
|
443
|
+
try {
|
|
444
|
+
const response = await executeGraphQLQuery({
|
|
445
|
+
query: effectiveQuery,
|
|
446
|
+
itemId: options.item.id,
|
|
447
|
+
language: options.item.language,
|
|
448
|
+
version: options.item.version,
|
|
449
|
+
mode: "edit",
|
|
450
|
+
siteName: "website",
|
|
451
|
+
schema: "Default",
|
|
452
|
+
});
|
|
453
|
+
return {
|
|
454
|
+
...response,
|
|
455
|
+
error: response.status && response.status !== 200 && !response.errors
|
|
456
|
+
? "GraphQL request failed"
|
|
457
|
+
: undefined,
|
|
458
|
+
warning,
|
|
459
|
+
compiledQuery: effectiveQuery,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
catch (error) {
|
|
463
|
+
return {
|
|
464
|
+
error: error instanceof Error ? error.message : String(error),
|
|
465
|
+
warning,
|
|
466
|
+
compiledQuery: effectiveQuery,
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
export async function fetchGraphiQLSchema(item) {
|
|
471
|
+
const response = await getGraphQLSchema({
|
|
472
|
+
id: item.id,
|
|
473
|
+
language: item.language,
|
|
474
|
+
version: item.version,
|
|
475
|
+
mode: "edit",
|
|
476
|
+
siteName: "website",
|
|
477
|
+
});
|
|
478
|
+
if (response.error) {
|
|
479
|
+
return {
|
|
480
|
+
status: response.status,
|
|
481
|
+
error: response.error,
|
|
482
|
+
transport: response.transport,
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
try {
|
|
486
|
+
const rawSchemaText = response.data ?? "";
|
|
487
|
+
const parsedSchema = rawSchemaText ? JSON.parse(rawSchemaText) : undefined;
|
|
488
|
+
return {
|
|
489
|
+
data: parsedSchema,
|
|
490
|
+
schema: parsedSchema ? buildClientSchema(parsedSchema) : undefined,
|
|
491
|
+
status: response.status,
|
|
492
|
+
transport: response.transport,
|
|
493
|
+
rawSchemaText,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
return {
|
|
498
|
+
status: response.status,
|
|
499
|
+
error: error instanceof Error
|
|
500
|
+
? `Schema parsing failed: ${error.message}`
|
|
501
|
+
: "Schema parsing failed.",
|
|
502
|
+
transport: response.transport,
|
|
503
|
+
rawSchemaText: response.data,
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
export function getSchemaContextValue(schemaResult) {
|
|
508
|
+
if (schemaResult.data) {
|
|
509
|
+
return JSON.stringify(schemaResult.data, null, 2);
|
|
510
|
+
}
|
|
511
|
+
if (schemaResult.rawSchemaText) {
|
|
512
|
+
return schemaResult.rawSchemaText;
|
|
513
|
+
}
|
|
514
|
+
if (schemaResult.error) {
|
|
515
|
+
return schemaResult.error;
|
|
516
|
+
}
|
|
517
|
+
return "";
|
|
518
|
+
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EAKpB,MAAM,gBAAgB,CAAC;AA4ExB,eAAO,MAAM,2BAA2B,mBAAmB,CAAC;AAC5D,eAAO,MAAM,+BAA+B,yBAAyB,CAAC;AAkCtE;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,mBAAmB,uBAoBxE;AAED,wBAAgB,eAAe,CAAC,aAAa,EAAE,mBAAmB,uBA6BjE;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,mBAAmB,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,53 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { lazy, Suspense } from "react";
|
|
3
|
-
import { Activity, Waypoints } from "lucide-react";
|
|
3
|
+
import { Activity, PanelsTopLeft, Waypoints } from "lucide-react";
|
|
4
|
+
import { GraphQLIcon, JsonIcon, } from "@parhelia/core";
|
|
5
|
+
import { Layout } from "./Layout";
|
|
4
6
|
import { alpacaComponentCommandProvider } from "./componentCommands";
|
|
5
7
|
import { TracingTitlebar } from "./tracing/components/TracingTitlebar";
|
|
6
8
|
import { TraceSourcesSidebar } from "./tracing/components/TraceSourcesSidebar";
|
|
9
|
+
const GraphQL = lazy(() => import("./GraphQL").then((module) => ({ default: module.GraphQL })));
|
|
10
|
+
function LazyGraphQLPanel() {
|
|
11
|
+
return (_jsx(Suspense, { fallback: _jsx("div", { className: "p-4 text-sm text-muted-foreground", children: "Loading GraphQL editor..." }), children: _jsx(GraphQL, {}) }));
|
|
12
|
+
}
|
|
7
13
|
const TracingWorkspaceComponent = lazy(() => import("./tracing/components/TracingWorkspace").then((module) => ({
|
|
8
14
|
default: module.TracingWorkspace,
|
|
9
15
|
})));
|
|
10
16
|
function LazyTracingWorkspace() {
|
|
11
17
|
return (_jsx(Suspense, { fallback: _jsx("div", { className: "p-4 text-sm text-muted-foreground", children: "Loading tracing\u2026" }), children: _jsx(TracingWorkspaceComponent, {}) }));
|
|
12
18
|
}
|
|
19
|
+
const layoutDebugSidebar = {
|
|
20
|
+
id: "layout",
|
|
21
|
+
title: "Layout",
|
|
22
|
+
icon: _jsx(PanelsTopLeft, { strokeWidth: 1 }),
|
|
23
|
+
position: "left",
|
|
24
|
+
sortOrder: 100,
|
|
25
|
+
panels: [
|
|
26
|
+
{
|
|
27
|
+
name: "layout",
|
|
28
|
+
icon: _jsx(JsonIcon, {}),
|
|
29
|
+
title: "Layout",
|
|
30
|
+
content: _jsx(Layout, {}),
|
|
31
|
+
initialSize: 100,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
const graphqlSidebar = {
|
|
36
|
+
id: "graphql",
|
|
37
|
+
title: "GraphQL",
|
|
38
|
+
icon: _jsx(GraphQLIcon, {}),
|
|
39
|
+
position: "left",
|
|
40
|
+
sortOrder: 101,
|
|
41
|
+
panels: [
|
|
42
|
+
{
|
|
43
|
+
name: "graphql",
|
|
44
|
+
icon: _jsx(GraphQLIcon, {}),
|
|
45
|
+
title: "GraphQL",
|
|
46
|
+
content: _jsx(LazyGraphQLPanel, {}),
|
|
47
|
+
initialSize: 100,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
13
51
|
export const ALPACA_TRACING_WORKSPACE_ID = "alpaca-tracing";
|
|
14
52
|
export const ALPACA_TRACE_SOURCES_SIDEBAR_ID = "alpaca-trace-sources";
|
|
15
53
|
const traceSourcesSidebar = {
|
|
@@ -64,11 +102,16 @@ export function configureAlpacaTracing(configuration) {
|
|
|
64
102
|
}
|
|
65
103
|
export function configureAlpaca(configuration) {
|
|
66
104
|
const sidebars = (configuration.editor?.sidebars || []).filter((s) => s.id !== "debug");
|
|
67
|
-
|
|
68
|
-
|
|
105
|
+
const hasLayoutDebugSidebar = sidebars.some((s) => s.id === layoutDebugSidebar.id);
|
|
106
|
+
const hasGraphqlSidebar = sidebars.some((s) => s.id === graphqlSidebar.id);
|
|
107
|
+
const nextSidebars = [...sidebars];
|
|
108
|
+
if (!hasLayoutDebugSidebar)
|
|
109
|
+
nextSidebars.push(layoutDebugSidebar);
|
|
110
|
+
if (!hasGraphqlSidebar)
|
|
111
|
+
nextSidebars.push(graphqlSidebar);
|
|
69
112
|
configuration.editor = {
|
|
70
113
|
...configuration.editor,
|
|
71
|
-
sidebars,
|
|
114
|
+
sidebars: nextSidebars,
|
|
72
115
|
};
|
|
73
116
|
const componentCommandProviders = configuration.componentCommands?.providers ?? [];
|
|
74
117
|
if (!componentCommandProviders.includes(alpacaComponentCommandProvider)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAQ,MAAM,gBAAgB,CAAC;AAEtD,wBAAsB,WAAW,CAAC,IAAI,EAAE,cAAc,gBAQrD"}
|
package/dist/services.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { post } from "@parhelia/core";
|
|
2
|
+
export async function getPageJson(page) {
|
|
3
|
+
const response = await post("/alpaca/headless/layout", {
|
|
4
|
+
itemId: page.id,
|
|
5
|
+
language: page.language,
|
|
6
|
+
version: page.version,
|
|
7
|
+
mode: "preview",
|
|
8
|
+
});
|
|
9
|
+
return response.data?.page;
|
|
10
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TracingTitlebar.d.ts","sourceRoot":"","sources":["../../../src/tracing/components/TracingTitlebar.tsx"],"names":[],"mappings":"AAwBA,wBAAgB,eAAe,
|
|
1
|
+
{"version":3,"file":"TracingTitlebar.d.ts","sourceRoot":"","sources":["../../../src/tracing/components/TracingTitlebar.tsx"],"names":[],"mappings":"AAwBA,wBAAgB,eAAe,uCA2M9B;AAwED,wBAAgB,IAAI,CAAC,EACnB,OAAO,EACP,QAAQ,EACR,KAAe,EACf,MAAM,GACP,EAAE;IACD,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,+BAYA;AAED,wBAAgB,QAAQ,CAAC,EACvB,QAAQ,EACR,OAAO,EACP,WAAW,EACX,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,+BAgBA"}
|