Skip to content

Conversation

@santino
Copy link

@santino santino commented Dec 14, 2025

Background

Malformed persisted document IDs (e.g., "mytest~0.1.0~" missing hash) were causing 500 Internal Server Errors instead of proper 400 Bad Request responses. This violated HTTP semantics and provided a poor developer experience with unclear error messages.

Description

This PR adds comprehensive document ID validation to prevent 500 errors and ensure proper HTTP status codes are returned.

Changes made:

  • Core Validation (@graphql-hive/core): Added validateDocumentId() function in packages/libraries/core/src/client/persisted-documents.ts to validate document ID format before making CDN requests
  • Apollo Integration: Enhanced error handling in packages/libraries/apollo/src/index.ts to catch validation errors and return 400 responses with INVALID_DOCUMENT_ID error code
  • Yoga Integration: Leverages existing @graphql-yoga/plugin-persisted-operations error handling (no changes needed)
  • Test Coverage: Added comprehensive tests in both core and Apollo packages to verify validation behavior

Supported document ID formats:
name~version~hash (e.g., mytest~0.1.0~sha256:abc123)

Packages affected:
packages/libraries/core - Core validation logic
packages/libraries/apollo - Apollo Server integration
packages/libraries/yoga - Yoga integration (no changes needed)

Checklist

  • Input validation
  • Error handling and logging
  • Testing

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @santino, 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 robustness and developer experience when dealing with persisted GraphQL documents. By implementing strict validation for document IDs at the core level and integrating this validation into the Apollo plugin, the system now provides clear, client-side error messages (400 Bad Request) for malformed IDs, preventing server-side 500 errors and improving overall API predictability.

Highlights

  • Improved Error Handling: Malformed persisted document IDs now correctly return 400 Bad Request errors instead of 500 Internal Server Errors, aligning with HTTP semantics and providing clearer feedback.
  • Core Validation Logic: A new validateDocumentId() function has been introduced in @graphql-hive/core to enforce the expected name~version~hash format of document IDs.
  • Apollo Integration: The Apollo plugin now catches validation errors from the core library and translates them into GraphQL errors with an INVALID_DOCUMENT_ID code and a 400 HTTP status extension.
  • Comprehensive Testing: New test cases have been added in both core and Apollo packages to ensure the validation logic and error handling work as expected for various malformed ID scenarios.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
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 effectively addresses the issue of malformed persisted document IDs causing 500 errors by introducing validation and proper error handling. The changes in @graphql-hive/core and @graphql-hive/apollo are well-implemented, and the added tests provide good coverage. I have a few suggestions to enhance correctness and maintainability.

@n1ru4l
Copy link
Contributor

n1ru4l commented Dec 15, 2025

Hey @santino, thank you for this contribution! Can you please add a changeset with a brief description of the changes for the affected packages using pnpm changeset? There also seems to be some TypeScript errors occuring!

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.

Malformed requests are returned as 500s

2 participants