in packages/graph-explorer/src/connector/sparql/vertexDetails.ts [26:86]
export async function vertexDetails(
sparqlFetch: SparqlFetch,
request: VertexDetailsRequest
): Promise<VertexDetailsResponse> {
const template = query`
# Get the resource attributes and class
SELECT *
WHERE {
{
# Get the resource attributes
SELECT ?label ?value
WHERE {
${idParam(request.vertexId)} ?label ?value .
FILTER(isLiteral(?value))
}
}
UNION
{
# Get the resource type
SELECT ?label ?value
WHERE {
${idParam(request.vertexId)} a ?value .
BIND(IRI("${rdfTypeUri}") AS ?label)
}
}
}
`;
// Fetch the vertex details
const response = await sparqlFetch(template);
if (isErrorResponse(response)) {
logger.error("Vertex details request failed", request, response);
throw new Error("Vertex details request failed", {
cause: response,
});
}
// Parse the response
const parsed = vertexDetailsResponseSchema.safeParse(response);
if (!parsed.success) {
logger.error(
"Failed to parse sparql response",
response,
parsed.error.issues
);
throw new Error("Failed to parse sparql response", {
cause: parsed.error,
});
}
// Map the results
if (parsed.data.results.bindings.length === 0) {
logger.warn("Vertex not found", request.vertexId, response);
return { vertex: null };
}
const vertex = mapToVertex(request.vertexId, parsed.data.results.bindings);
return { vertex };
}