0
0
GraphQLquery~5 mins

Partial success responses in GraphQL

Choose your learning style9 modes available
Introduction

Partial success responses let you get some data even if part of your request fails. This helps keep your app working smoothly without stopping everything.

When fetching multiple items and some might not be available but you still want the rest.
When calling a service that might return errors for some parts but still returns useful data.
When you want to show users partial results instead of a full error message.
When integrating with APIs that can return partial data with error details.
When debugging or testing to see which parts of a query succeed or fail.
Syntax
GraphQL
{
  "data": {
    "someField": {
      "subfield": "value"
    }
  },
  "errors": [
    {
      "message": "Error in some part",
      "path": ["someField", "failedSubfield"]
    }
  ]
}
Partial success is not a special syntax but a pattern where the response includes both data and errors fields.
The errors field contains details about what failed, while data contains what succeeded.
Examples
This query fetches a user and their posts. If some posts fail to load, the response may include partial data with errors.
GraphQL
query {
  user(id: "1") {
    name
    posts {
      title
    }
  }
}
Fetching multiple products. If one product ID is invalid, the response can return data for valid products and errors for invalid ones.
GraphQL
query {
  products(ids: ["1", "2", "3"]) {
    id
    name
  }
}
Sample Program

This query asks for two books by ID. If book with ID "999" does not exist, the response will include the existing book and an error for the missing one.

GraphQL
query {
  books(ids: ["1", "999"]) {
    id
    title
  }
}
OutputSuccess
Important Notes

Partial success responses help improve user experience by showing available data.

Always check both data and errors in the response to handle issues properly.

Not all GraphQL servers support partial success; it depends on the implementation.

Summary

Partial success responses return both data and errors together.

This allows apps to use available data even if some parts fail.

Check the errors field to understand what went wrong.