Skip to content

Conversation

ardatan
Copy link
Member

@ardatan ardatan commented Oct 13, 2025

Ref ROUTER-155
Ref ROUTER-156

  • When validate_runtime_value takes null for a non-nullable scalar type, it was throwing like;
    Failed to collect GraphQL variables: Expected a string for type 'String', got Null

  • When the list input value receives non-list value, it should be treated as a one-item list.

type Query {
  foo(bar: [String]): String
}

In this case if you have an operation like below;

{
   "query": "query Foo($bar: [String]) {
       foo(bar: $bar)
   }
}

And then variables like { "bar": "BAR" }
it should be treated as ["BAR"]

Copy link
Contributor

Summary of Changes

Hello @ardatan, 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 addresses an issue where the GraphQL variable validation process incorrectly rejected null values for types that are defined as nullable. The changes ensure that null is properly accepted during runtime value validation for both scalar and list types, aligning the validator's behavior with GraphQL's nullable type specifications and resolving the reported error (ROUTER-155).

Highlights

  • Variable Validation Logic: Modified the validate_runtime_value function to correctly handle null values for nullable scalar and list types. Previously, providing null for these types would result in an error, even if the schema allowed it. The updated logic now explicitly permits null values to pass validation for TypeNode::Named and TypeNode::List.
  • Test Coverage: Added a new unit test, allow_null_values_for_scalar_non_nullable_types, to verify that null values are successfully validated for various scalar types (String, Int, Float, Boolean, ID), ensuring the fix behaves as expected.
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.

@ardatan
Copy link
Member Author

ardatan commented Oct 13, 2025

@gemini-code-assist review and summary

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in variable validation where null values were incorrectly rejected for nullable scalar types. The validation function now properly accepts null values for scalar types like String, Int, Float, Boolean, and ID when they are not wrapped in a NonNull type.

Key changes:

  • Added early null checks for Named and List type nodes to allow null values
  • Added comprehensive test coverage for null validation on scalar types

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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 correctly adjusts variable validation to allow null values for nullable scalar and list types, aligning with GraphQL's nullability rules. The changes in validate_runtime_value are logical and are accompanied by a new test case. My review includes a suggestion to rename the test for clarity and another to add a test case for nullable list types to ensure full coverage of the changes. The PR description seems to have a minor mix-up between 'nullable' and 'non-nullable', but the code implementation is correct.

ardatan and others added 2 commits October 13, 2025 19:54
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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 correctly allows null values for nullable scalar and list types during variable validation, which fixes a bug where they were incorrectly rejected. My review includes a suggestion to refactor the implementation to reduce code duplication, a correction for a misleading test name, and a recommendation to add a missing test case for nullable list types to improve test coverage.

Copy link

github-actions bot commented Oct 13, 2025

k6-benchmark results

     ✓ response code was 200
     ✓ no graphql errors
     ✓ valid response structure

     █ setup

     checks.........................: 100.00% ✓ 223401      ✗ 0    
     data_received..................: 6.5 GB  217 MB/s
     data_sent......................: 87 MB   2.9 MB/s
     http_req_blocked...............: avg=3.87µs   min=661ns  med=1.75µs  max=10.54ms  p(90)=2.53µs  p(95)=2.93µs  
     http_req_connecting............: avg=1.03µs   min=0s     med=0s      max=8.31ms   p(90)=0s      p(95)=0s      
     http_req_duration..............: avg=19.66ms  min=1.9ms  med=18.71ms max=100.64ms p(90)=27.12ms p(95)=30.44ms 
       { expected_response:true }...: avg=19.66ms  min=1.9ms  med=18.71ms max=100.64ms p(90)=27.12ms p(95)=30.44ms 
     http_req_failed................: 0.00%   ✓ 0           ✗ 74487
     http_req_receiving.............: avg=143.11µs min=25.7µs med=40.29µs max=76.61ms  p(90)=90.01µs p(95)=389.03µs
     http_req_sending...............: avg=25.84µs  min=5.88µs med=10.86µs max=23.82ms  p(90)=16.77µs p(95)=28.25µs 
     http_req_tls_handshaking.......: avg=0s       min=0s     med=0s      max=0s       p(90)=0s      p(95)=0s      
     http_req_waiting...............: avg=19.49ms  min=1.84ms med=18.58ms max=80.69ms  p(90)=26.86ms p(95)=30.09ms 
     http_reqs......................: 74487   2478.239516/s
     iteration_duration.............: avg=20.13ms  min=4.28ms med=19.07ms max=237.05ms p(90)=27.57ms p(95)=30.9ms  
     iterations.....................: 74467   2477.574101/s
     vus............................: 50      min=50        max=50 
     vus_max........................: 50      min=50        max=50 

@ardatan ardatan changed the title Allow null value for nullable scalar types while validating variables fix(router): allow null value for nullable scalar types while validating variables Oct 13, 2025
Copy link

github-actions bot commented Oct 13, 2025

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

Image Names: ghcr.io/graphql-hive/router

Platforms: linux/amd64,linux/arm64

Image Tags: ghcr.io/graphql-hive/router:pr-483 ghcr.io/graphql-hive/router:sha-4d3751b

Docker metadata
{
"buildx.build.ref": "builder-1ba615dd-3fe6-40e7-82b6-c0273bb5cab1/builder-1ba615dd-3fe6-40e7-82b6-c0273bb5cab10/x8ejl8duq73b4zedx6vzyxpjx",
"containerimage.descriptor": {
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "digest": "sha256:9ce2ce1e0c00d2a27a44e29da0a9508cf1c5acca5e8cfca06ba0e7a26fac03a5",
  "size": 1609
},
"containerimage.digest": "sha256:9ce2ce1e0c00d2a27a44e29da0a9508cf1c5acca5e8cfca06ba0e7a26fac03a5",
"image.name": "ghcr.io/graphql-hive/router:pr-483,ghcr.io/graphql-hive/router:sha-4d3751b"
}

@ardatan ardatan enabled auto-merge (squash) October 13, 2025 17:56
@ardatan ardatan changed the title fix(router): allow null value for nullable scalar types while validating variables fix(router): allow null value for nullable scalar types while validating variables & coerce list variables Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant