Use explicit navigation projections for React presentation readiness (#339)
This commit is contained in:
parent
bc9a7ef2cf
commit
ee84025322
+27
-5
@@ -113,6 +113,13 @@ export function lowerQueryTree(
|
||||
if (!root || selection.some((field) => field !== root))
|
||||
throw new QueryCompileError("QUERY_TREE_ROOT", "A Query Tree requires one unaliased root selection");
|
||||
const plan: QueryTreePlan = { root: "root", nodes: [], projections: [], maxOccurrences: 0 };
|
||||
const collectionBound = (field: QuerySelection): number | undefined => {
|
||||
const limit = field.arguments.first ?? field.arguments.all;
|
||||
// Checked GraphQL Int literals retain their decimal spelling in the IR.
|
||||
if (limit?.kind !== "literal" || !["string", "number"].includes(typeof limit.value)) return;
|
||||
const value = Number(limit.value);
|
||||
return Number.isSafeInteger(value) && value > 0 ? Math.min(value, declaration.budgets.rows) : undefined;
|
||||
};
|
||||
const project = (id: string, subject: InterfaceRevisionId, fields: QuerySelection[], shape: ValueType) => {
|
||||
if (plan.projections.length >= 256)
|
||||
throw new QueryCompileError("QUERY_TREE_LIMIT", "Query Tree exceeds 256 projections");
|
||||
@@ -153,9 +160,15 @@ export function lowerQueryTree(
|
||||
for (const field of fields) {
|
||||
if (field.boundary || !containsBoundary(field.selection)) continue;
|
||||
const targets: { path: string[]; node: string }[] = [];
|
||||
const prune = (fields: QuerySelection[], shape: ValueType, path: string[], bound: number): QuerySelection[] => {
|
||||
if (shape.kind === "optional") return prune(fields, shape.value, path, bound);
|
||||
if (shape.kind === "list") return prune(fields, shape.value, [...path, "[]"], bound * declaration.budgets.rows);
|
||||
const prune = (
|
||||
fields: QuerySelection[],
|
||||
shape: ValueType,
|
||||
path: string[],
|
||||
bound: number,
|
||||
listLimit = declaration.budgets.rows,
|
||||
): QuerySelection[] => {
|
||||
if (shape.kind === "optional") return prune(fields, shape.value, path, bound, listLimit);
|
||||
if (shape.kind === "list") return prune(fields, shape.value, [...path, "[]"], bound * listLimit);
|
||||
const target = objectInterface(fields);
|
||||
if (target) {
|
||||
targets.push({
|
||||
@@ -168,7 +181,13 @@ export function lowerQueryTree(
|
||||
.filter((field) => containsBoundary(field.selection))
|
||||
.map((field) => ({
|
||||
...field,
|
||||
selection: prune(field.selection, fieldType(shape, field.key), [...path, field.key], bound),
|
||||
selection: prune(
|
||||
field.selection,
|
||||
fieldType(shape, field.key),
|
||||
[...path, field.key],
|
||||
bound,
|
||||
collectionBound(field) ?? listLimit,
|
||||
),
|
||||
}));
|
||||
// Relationship occurrence identity is its entry key, including duplicate
|
||||
// target Objects. Never substitute list position or Object identity.
|
||||
@@ -177,7 +196,10 @@ export function lowerQueryTree(
|
||||
return minimal;
|
||||
};
|
||||
const type = fieldType(shape, field.key);
|
||||
const minimal = { ...field, selection: prune(field.selection, type, [field.key], occurrences) };
|
||||
const minimal = {
|
||||
...field,
|
||||
selection: prune(field.selection, type, [field.key], occurrences, collectionBound(field)),
|
||||
};
|
||||
const selected = [...identity(fields), minimal];
|
||||
current.bindings.push({
|
||||
name: field.key,
|
||||
|
||||
Reference in New Issue
Block a user