Skip to content

fix(graphql): Prevent ZodError from undefined GraphQL responses - #4129

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/graphql-zod-error
Open

sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/graphql-zod-error

Conversation

@sentry

@sentry sentry Bot commented Sep 16, 2026

Copy link
Copy Markdown

Description

This PR addresses a ZodError occurring in the useUser hook when UserSchema.safeParse receives undefined.

Code Example

Notable Changes

Problem: The GraphQL API can return a 200 HTTP status code, but with a response body containing only an errors field (e.g., {"errors": [...]}) and no data field. Previously, the graphql() function in src/shared/api/api.ts would resolve the promise with this errors-only response. When res?.data was accessed in useUser, it would evaluate to undefined, leading to UserSchema.safeParse(undefined) and the observed ZodError.

Solution: The graphql() function in src/shared/api/api.ts has been modified. It now explicitly rejects the promise if a GraphQL response (even with a 200 status) contains errors but lacks a data field. This ensures that downstream consumers, such as the useUser hook and its Zod schema validation, never receive undefined when an object is expected, thereby preventing the ZodError.

Screenshots

Link to Sample Entry

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes GAZEBO-1879

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
5754 1 5753 3
View the top 1 failed test(s) by shortest run time
src/pages/AccountSettings/tabs/YAML/YAML.test.jsx > YAMLTab > The api fails > The save button becomes unsaved changes and an error is displayed
Stack Traces | 1.06s run time
TestingLibraryElementError: Unable to find an element with the text: /Something went wrong/. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

Ignored nodes: comments, script, style
<body
  class=""
>
  <div />
</body>

Ignored nodes: comments, script, style
<body
  class=""
>
  <div />
</body>
 ❯ waitForWrapper node_modules/@.../dom/dist/wait-for.js:163:27
 ❯ node_modules/@.../dom/dist/query-helpers.js:86:33
 ❯ .../tabs/YAML/YAML.test.jsx:225:47

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@sentry

sentry Bot commented Sep 16, 2026

Copy link
Copy Markdown
Author

⚠️ Seer needs additional GitHub permissions

Seer wants to keep iterating on this pull request to get CI passing, but the Sentry GitHub App installation is missing permissions it needs to read the failing checks and push a fix.

Review and accept the updated permissions to let Seer continue: https://github.com/organizations/codecov/settings/installations/86101127/permissions/update

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 124 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
gazebo-production-system 5.82MB 62 bytes (0.0%) ⬆️
gazebo-production-esm 5.89MB 62 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: gazebo-production-system

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-legacy.*.js 62 bytes 657.88kB 0.01%

Files in assets/index-legacy.*.js:

  • ./src/shared/api/api.ts → Total Size: 2.48kB
view changes for bundle: gazebo-production-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index.*.js 62 bytes 577.87kB 0.01%

Files in assets/index.*.js:

  • ./src/shared/api/api.ts → Total Size: 2.46kB

@codecov-public-qa

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
5754 1 5753 3
View the top 1 failed test(s) by shortest run time
src/pages/AccountSettings/tabs/YAML/YAML.test.jsx > YAMLTab > The api fails > The save button becomes unsaved changes and an error is displayed
Stack Traces | 1.06s run time
TestingLibraryElementError: Unable to find an element with the text: /Something went wrong/. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

Ignored nodes: comments, script, style
<body
  class=""
>
  <div />
</body>

Ignored nodes: comments, script, style
<body
  class=""
>
  <div />
</body>waitForWrapper node_modules/@.../dom/dist/wait-for.js:163:27node_modules/@.../dom/dist/query-helpers.js:86:33
 ❯ .../tabs/YAML/YAML.test.jsx:225:47

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@codecov-releaser

Copy link
Copy Markdown
Collaborator

✅ Deploy preview for gazebo ready!

Previews expire after 1 month automatically.

Storybook

Commit Created Cloud Enterprise
73e241e Wed, 16 Sep 2026 19:23:30 GMT Cloud Enterprise

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