Skip to content

Conversation

@sabrahul
Copy link
Contributor

@sabrahul sabrahul commented Mar 24, 2025

Added partial error response details in error guides

Description

This PR enhances the Dealing with Errors documentation by adding details about partial error responses. It addresses an issue where a single resolver failure causes the entire GraphQL response to be null instead of returning partial data. The update explains the expected behavior and highlights the importance of using Optional types in field resolvers to ensure partial responses are correctly handled.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Document how Strawberry handles partial responses when a resolver fails, and explain how to use Optional types to ensure partial responses are correctly handled.

Enhancements:

  • Explain how Strawberry handles partial responses when a resolver fails.
  • Recommend the use of Optional types in field resolvers to ensure partial responses are correctly handled.

Added partial error response details in error guides
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 24, 2025

Reviewer's Guide by Sourcery

This pull request enhances the 'Dealing with Errors' documentation by adding a section about partial error responses. It explains how GraphQL handles resolver failures by returning partial data when fields are defined as optional, and provides an example to illustrate this behavior.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Added a section explaining partial responses for failed resolvers, detailing how GraphQL returns both successful data and error details when a resolver fails, provided the field is optional.
  • Introduced the 'Partial responses for failed resolvers' section.
  • Explained that GraphQL allows partial responses when a resolver fails, returning successfully resolved fields alongside errors.
  • Emphasized that this behavior applies only when the erroneous field is defined as optional.
  • Provided a Python example with successful_field and error_field to demonstrate partial responses.
  • Included a GraphQL query to fetch both fields.
  • Showed the JSON response with data for successfulField, null for errorField, and error details.
  • Highlighted GraphQL's ability to return partial results.
docs/guides/errors.md

Assessment against linked issues

Issue Objective Addressed Explanation
#3814 Document the behavior of strawberry-graphql regarding partial responses when a resolver throws an error.
#3814 Explain how to ensure partial responses are returned when some resolvers fail in a query.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @sabrahul - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a note about how to configure Strawberry to always return partial responses, even for non-optional fields.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Member

@patrick91 patrick91 left a comment

Choose a reason for hiding this comment

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

This is perfect! Thank you!

@patrick91
Copy link
Member

add failed in .alexrc
@sabrahul
Copy link
Contributor Author

Hi @patrick91, I have added what you've asked. Is there something else we need to do?

@patrick91
Copy link
Member

@sabrahul no, all good! thanks!

@patrick91 patrick91 merged commit de07ab6 into strawberry-graphql:main Mar 25, 2025
4 checks passed
@botberry
Copy link
Member

Thanks for contributing to Strawberry! 🎉 You've been invited to join
the Strawberry GraphQL organisation 😊

You can also request a free sticker by filling this form: https://forms.gle/dmnfQUPoY5gZbVT67

And don't forget to join our discord server: https://strawberry.rocks/discord 🔥

amlimaye pushed a commit to Tyba-Energy/strawberry that referenced this pull request Mar 31, 2025
* Update errors.md

Added partial error response details in error guides

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update .alexrc

add failed in .alexrc

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

Resolver error nulls other resolvers

3 participants