Comments (1)
Hi @radosavljevic, thanks for using the module and for taking the time to open an issue.
It looks to me that what you're describing as an issue for improvement is expected behavior, by design.
As described in the documentation and in the comments in the code section you mentioned, we consider a GraphQL response to be a REST error only if there's a non-empty errors
array, AND the data
object is missing, null, or empty, or all its keys are null/undefined.
The rationale behind it is that while in REST HTTP a request can either succeed (2XX status) or fail (4XX or 5XX status), in GraphQL a request can partially succeed (or fail). This can happen, for example, when we get a full data
object in the response but one field is null
because the specific resolver for that field has failed, while all other fields have full, expected values. In this case an errors
array will include the error details for that specific resolver/field. We would not want to classify this response as an error and fail the request with a 4XX or 5XX error code, denying the client of the data (when a client sees a non-2XX status code they usually ignore the data). This can perhaps be classified as a "warning", if there was ever a notion of warnings in REST (or GraphQL...).
This is especially common in the case of GraphQL2REST, where generated client queries are "fully exploded queries" including all possible fields, so it's not uncommon for one sometimes unused client field/resolver to fail, generating a completely usable response but also a non-null errors
array. We would not want to fail the REST operation wrapping it in that case. So that's why I adopted that logic. In any case graphql2rest
logs will show the original response from GraphQL including the errors
array, for debugging purposes.
Also see this article for reference: https://itnext.io/the-definitive-guide-to-handling-graphql-errors-e0c58b52b5e1
I saw your fork changed this logic, which might be required for your purposes. In any case let me know if this is clear so I can close the issue as "not a bug". Thanks!!
from graphql2rest.
Related Issues (19)
- Hangs on large schema? HOT 2
- Passing query params into gql HOT 7
- Rest API document HOT 3
- Issue in generated GQL files HOT 1
- Split test module into smaller modules HOT 1
- Add types file for logger integration
- filterResponse() and attachCustomError() assume data/error format and might fail on different format
- Add GitHub action: publish npm package
- Add GitHub actions: continuous integration HOT 2
- Feature Request: Add support for GraphQL subscriptions
- Feature Request: add support for OpenAPI/Swagger auto-generation HOT 6
- Field Filtering Is Done After Object Is Returned HOT 3
- Query parameters don't get converted to appropriate GraphQL types HOT 6
- Generate only relevant gql files HOT 1
- TypeError: field.type.inspect is not a function HOT 9
- formatError on ApolloServer not being applied in graphql2rest HOT 1
- Is this repo being maintained? HOT 4
- code chage to make middlewaresFile a middlewaresModule (optionally) instead HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql2rest.