Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Fix error handler in graphql client #1330

Merged
merged 3 commits into from
Apr 8, 2024
Merged

Conversation

5n00p4eg
Copy link
Contributor

@5n00p4eg 5n00p4eg commented Apr 5, 2024

WHY are these changes introduced?

In some cases, fetch response is not available for error handling, so type error appears:

TypeError: Cannot read properties of undefined (reading 'headers')

Related issues: Shopify/shopify-app-js#764

WHAT is this pull request doing?

In case of response object is not avaliabe GraphqlQueryError is raised directly with outer response data.

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have used yarn changeset to create a draft changelog entry (do NOT update the CHANGELOG.md file manually)
  • I have added/updated tests for this change
  • I have documented new APIs/updated the documentation for modified APIs (for public APIs)

@paulomarg
Copy link
Contributor

paulomarg commented Apr 5, 2024

Thank you so much for contributing, we appreciate it! I think this is the right idea, but I have some thoughts:

  1. There are a few other places that use this same logic, we should probably not assume we get a response in all of them. I think it would be better to have this code inside of throwFailedRequest. We could make response accept Response | undefined and then throw first thing if no response is present. That way all of these cases would behave the same way.
  2. We should have a test for this case, at least for the admin and storefront clients - you can use queueError instead of queueMockResponse in the test file to trigger this scenario

@5n00p4eg
Copy link
Contributor Author

5n00p4eg commented Apr 8, 2024

@paulomarg Take a look, please

Copy link
Contributor

@paulomarg paulomarg left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

@paulomarg paulomarg merged commit a944d7b into Shopify:main Apr 8, 2024
6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants