Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the GraphQL Laboratory by integrating a comprehensive query plan visualization feature. Users can now inspect the execution plan of their GraphQL queries, viewing it either as a formatted text output or an interactive visual flow diagram. This addition is complemented by new configuration options in the laboratory settings, allowing for fine-grained control over network requests, subscription protocols, and introspection behavior, ultimately providing a more powerful and insightful development experience. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
🚀 Snapshot Release (
|
| Package | Version | Info |
|---|---|---|
@graphql-hive/laboratory |
0.1.3-alpha-20260324120101-4dcadfd8ad718bb47fd5cc9219b911a1d5c37896 |
npm ↗︎ unpkg ↗︎ |
@graphql-hive/render-laboratory |
0.1.3-alpha-20260324120101-4dcadfd8ad718bb47fd5cc9219b911a1d5c37896 |
npm ↗︎ unpkg ↗︎ |
hive |
11.0.0-alpha-20260324120101-4dcadfd8ad718bb47fd5cc9219b911a1d5c37896 |
npm ↗︎ unpkg ↗︎ |
|
🐋 This PR was built and pushed to the following Docker images: Targets: Platforms: Image Tag: |
There was a problem hiding this comment.
Code Review
This pull request introduces a query plan visualizer, a significant feature. My review focuses on improving correctness, performance, and adherence to the repository's guidelines. I've identified several areas for improvement, including dependency management, performance optimization in the new flow component, safer data handling and parsing, and ensuring robust UI rendering. The most critical issues relate to dependency correctness and the lack of data validation for the query plan, which could lead to runtime errors.
| } | ||
|
|
||
| lines.push(`${indent(depth + 1)}operation {`); | ||
| lines.push(renderMultilineBlock(print(parse(node.operation)), depth + 2)); |
There was a problem hiding this comment.
The parse function from graphql can throw an error if the operation string is not a valid GraphQL document. This would crash the rendering of the query plan. It's safer to wrap this call in a try...catch block.
try {
lines.push(renderMultilineBlock(print(parse(node.operation)), depth + 2));
} catch {
// Fallback to showing the raw operation string if parsing fails
lines.push(renderMultilineBlock(node.operation, depth + 2));
}
| const findFollowers = useCallback( | ||
| (nodeId: string): FlowNode[] => { | ||
| const node = nodes.find(node => node.id === nodeId); | ||
|
|
||
| if (!node) { | ||
| return [] as FlowNode[]; | ||
| } | ||
|
|
||
| return ( | ||
| (node.next | ||
| ?.map(next => { | ||
| return [nodes.find(node => node.id === next), ...findFollowers(next)].filter(Boolean); | ||
| }) | ||
| .flat(Infinity) as FlowNode[]) ?? [] | ||
| ); | ||
| }, | ||
| [nodes], |
There was a problem hiding this comment.
The current implementation of findFollowers is inefficient due to repeated nodes.find() calls within a recursive function. This can lead to poor performance on larger graphs.
To optimize this, you can create a Map of nodes by their ID once (ideally in the useMemo where nodes are created) and then use an iterative approach (like BFS) to find followers. This avoids repeated O(N) searches and handles complex graph structures more efficiently.
const findFollowers = useCallback(
(nodeId: string): FlowNode[] => {
const nodesById = new Map(nodes.map(n => [n.id, n]));
const startNode = nodesById.get(nodeId);
if (!startNode) {
return [];
}
const followers = new Set<FlowNode>();
const queue: string[] = [...(startNode.next ?? [])];
const visited = new Set<string>(queue);
while (queue.length > 0) {
const currentId = queue.shift()!;
const currentNode = nodesById.get(currentId);
if (currentNode) {
followers.add(currentNode);
if (currentNode.next) {
for (const nextId of currentNode.next) {
if (!visited.has(nextId)) {
visited.add(nextId);
queue.push(nextId);
}
}
}
}
}
return Array.from(followers);
},
[nodes],
);
| export const queryPlanNodeIcon = ( | ||
| kind: QueryPlanNode['kind'], | ||
| ): ((props: LucideProps) => React.ReactNode) => { | ||
| return (props: LucideProps) => { | ||
| switch (kind) { | ||
| case 'Root': | ||
| return <GraphQLIcon {...props} />; | ||
| case 'Fetch': | ||
| return <Box {...props} />; | ||
| case 'BatchFetch': | ||
| return <Boxes {...props} />; | ||
| case 'Flatten': | ||
| return <Layers2Icon {...props} />; | ||
| case 'Sequence': | ||
| return <ListOrderedIcon {...props} />; | ||
| case 'Parallel': | ||
| return <NetworkIcon {...props} />; | ||
| case 'Condition': | ||
| return <GitForkIcon {...props} className={cn('rotate-90', props.className)} />; | ||
| case 'Subscription': | ||
| return <UnlinkIcon {...props} />; | ||
| case 'Defer': | ||
| return <ClockIcon {...props} />; | ||
| } | ||
| }; | ||
| }; |
There was a problem hiding this comment.
The switch statement in queryPlanNodeIcon is missing a default case. If a new node kind is added in the future, this function will return undefined and cause a rendering error. Adding a default case that returns null or a fallback icon will make this component more robust.
export const queryPlanNodeIcon = (
kind: QueryPlanNode['kind'],
): ((props: LucideProps) => React.ReactNode) => {
return (props: LucideProps) => {
switch (kind) {
case 'Root':
return <GraphQLIcon {...props} />;
case 'Fetch':
return <Box {...props} />;
case 'BatchFetch':
return <Boxes {...props} />;
case 'Flatten':
return <Layers2Icon {...props} />;
case 'Sequence':
return <ListOrderedIcon {...props} />;
case 'Parallel':
return <NetworkIcon {...props} />;
case 'Condition':
return <GitForkIcon {...props} className={cn('rotate-90', props.className)} />;
case 'Subscription':
return <UnlinkIcon {...props} />;
case 'Defer':
return <ClockIcon {...props} />;
default:
return null;
}
};
};
… into feat/lab-query-plan
bae6f49 to
143a2f0
Compare
28be2aa to
4dcadfd
Compare
3542566 to
cde3cb8
Compare
cde3cb8 to
7f23520
Compare
Background
Description
Hive Laboratory to render Hive Router query plan if it's part of response
Screen.Recording.2026-03-23.at.23.13.38.mov
Checklist