Skip to content

Feat/lab query plan#7892

Draft
mskorokhodov wants to merge 4 commits intomainfrom
feat/lab-query-plan
Draft

Feat/lab query plan#7892
mskorokhodov wants to merge 4 commits intomainfrom
feat/lab-query-plan

Conversation

@mskorokhodov
Copy link
Copy Markdown
Collaborator

@mskorokhodov mskorokhodov commented Mar 20, 2026

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

  • Input validation
  • Output encoding
  • Authentication management
  • Session management
  • Access control
  • Cryptographic practices
  • Error handling and logging
  • Data protection
  • Communication security
  • System configuration
  • Database security
  • File management
  • Memory management
  • Testing

@mskorokhodov mskorokhodov marked this pull request as draft March 20, 2026 21:23
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Query Plan Visualization: Introduced a new feature to visualize GraphQL query plans within the laboratory environment, offering both text and interactive visual representations.
  • Graph Flow Component: Implemented a reusable Flow component for rendering directed graphs, which is utilized by the visual query plan display.
  • Expanded Laboratory Settings: Added new configuration options for fetch behavior (timeout, retry, use GET for queries), subscription protocols, and introspection settings.
  • Dependency Updates: Updated and added graph-related dependencies, specifically dagrejs and @dagrejs/dagre, to support graph layout algorithms.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 20, 2026

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

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 ↗︎

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 20, 2026

🐋 This PR was built and pushed to the following Docker images:

Targets: build

Platforms: linux/amd64

Image Tag: 4dcadfd8ad718bb47fd5cc9219b911a1d5c37896

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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));
  }

Comment on lines +133 to +149
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],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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],
);

Comment on lines +663 to +688
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} />;
}
};
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;
    }
  };
};

@mskorokhodov mskorokhodov force-pushed the feat/lab-query-plan branch 5 times, most recently from bae6f49 to 143a2f0 Compare March 23, 2026 22:18
@mskorokhodov mskorokhodov marked this pull request as ready for review March 23, 2026 22:21
@mskorokhodov mskorokhodov force-pushed the feat/lab-query-plan branch 5 times, most recently from 28be2aa to 4dcadfd Compare March 24, 2026 11:59
@theguild-bot theguild-bot deployed to development March 24, 2026 13:07 Active
@n1ru4l n1ru4l marked this pull request as draft March 25, 2026 07:36
@mskorokhodov mskorokhodov force-pushed the feat/lab-query-plan branch 3 times, most recently from 3542566 to cde3cb8 Compare March 26, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants