Skip to content

Graph queries and view references

A handler reads the owner’s graph with ctx.gateway.cypher.query. The generated types leave cypher as unknown, so give the call a type in the handler:

import type { OpenBySeverityHandler } from "../.embabel/realm.d.ts";
interface CypherGateway {
cypher: {
query(request: { cypher: string; params?: Record<string, unknown> }): Promise<{
rows: Record<string, unknown>[];
warnings: unknown[];
}>;
};
}
export const openBySeverity: OpenBySeverityHandler = async (input, ctx) => {
const gateway = ctx.gateway as unknown as CypherGateway;
const { rows } = await gateway.cypher.query({
cypher: `MATCH (s:Service)-[:HAS_INCIDENT]->(i:Incident)
WHERE s.team = $team AND i.impact IN $impacts
RETURN s.name AS service, i.incidentId AS incident
LIMIT 100`,
params: { team: input.team, impacts: ["critical", "major"] },
});
return { rows };
};
  • The owner approves cypher_query on its own. Approving a handler never grants it.
  • It resolves to {rows, warnings, coverage}; coverage is empty in this profile.
  • Pass every value through params. userId, worldId, workspaceId and names starting with __ are refused as parameters.
  • Give every node you bind a label and a variable name, and end the statement with a literal LIMIT from 1 to 512.
  • Only nodes the owner owns outright are visible. Nodes shared with the owner, variable-length and named paths, list and pattern comprehensions, procedures, and functions outside a fixed list are refused. The list and the size limits are in the graph-query profile.
  • The query may cross into the realm’s own producers, as above. Nothing a producer returns is kept.

A realm may also read the owner’s own named views, under aliases the owner approves one at a time:

queries: {
views: [{ alias: "services", view: "Services" }],
},

A statement may then write MATCH (s:services); the host inlines the view in its place. alias is [a-z][a-z0-9_]{0,63}, view is [A-Za-z][A-Za-z0-9_]{0,63}, and the list holds at most 32 entries, each alias and each view once. An empty list is written to the file too. A view that references another view, takes parameters or is materialized is refused. See view references.