Giter VIP home page Giter VIP logo

Comments (3)

ramonwenger avatar ramonwenger commented on May 29, 2024 2

Maybe storing errors is not the way to go, the abstraction of GraphQL errors is a bit messy. You could consider a different approach (not my article, but a worthy read)

from apollo-feature-requests.

aquark avatar aquark commented on May 29, 2024

I'm not sure that article is relevant, since it recommends a different approach for only some kinds of errors, not internal server errors for example. If you're suggesting that every individual field should be modeled as a union type and field resolvers can never throw exceptions, I don't think that's practical with GraphQL tooling as it exists today. It's just too cumbersome in most languages to handle union types on every field.

This feature request solves a specific problem with using cache-first fetch policy when the service returns an unexpected error, e.g. an internal server error. If the service returns partial data which is cached, then the first time you execute the query it will return the error, while later executions will return only the partial data and no error message, so the consuming component can no longer display the same information as it did the first time.

An example might be a page which shows user info. The first time you visit the page, it shows an error message about some missing data. If you leave the page and return, the data is still missing, but there is no error message. This is a confusing experience. From the perspective of the consuming component, the error is a part of the response, and to display the response correctly the component always needs both the error and the partial data.

On the other hand, I can understand why this is a hard problem to solve, because the cache operates at the level of fields while errors are modeled at the level of requests. For example, what should happen if a different query fetches some of the missing fields so the original query can return a more complete response -- should the original query still return the error which describes the reason for the originally missing fields? What if the response is eventually fully populated by other queries, does it still make sense to return the original error?

Ultimately it seems like this points to a fundamental misalignment between GraphQL semantics and the Apollo caching strategy, maybe even a problem with the GraphQL design itself. Maybe GraphQL should have treated every single field as an implicit union type, either an error or a value, so that errors are always represented within the structure of the data itself. Because that seems like the only way to make error handling consistent with the idea that every field can be fetched and cached independently.

from apollo-feature-requests.

ramonwenger avatar ramonwenger commented on May 29, 2024

@aquark Good point, and I wasn't suggesting that no error ever should be thrown, I was just suggesting an approach that helped me with handling of errors. But I just realized thanks to your reply that I probably completely missed the point of this feature request.

from apollo-feature-requests.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.