Comments (1)
Hi, this is a very good question, albeit mostly unrelated to the library IMHO.
You pointed out already that there is a natural distinction between domain errors and technical errors. We made good experience by modeling domain errors in the Graph itself. Clients usually want to display those in some form to the user whichis is rather tedious if you have to extract those from the errors field in the GraphQL response.
How you actually model it is up to you but I think you want to have the following properties:
- if the mutation failed with a domain error you want to stop execution at that level
- you likely want typed errors
- if all went well you want to just continue traversing the graph
One good way to do it seems to be a union type.
type SuccessData {
name: String
lastName: String
friends: SomeEdge
}
type ErrorData {
errors: [String] # you likely want better types here
}
union MyMutationResult = SuccessData | ErrorData
extend type Mutation {
myMutation: MutationResult
}
This could be used like this:
mutation DoIt {
myMutation {
... on SuccessData { name lastName }
... on ErrorData { errors }
}
}
Error representation is still one of the weak spots in GraphQL. So what I said is not a „standard“ way of doing things but rather the learnings me and my team have after having built, evolved and operated our GraphQL gateway in production for the last ~2years. We actually don’t use unions but specialised execution that is turned on with directives but the underlying idea remains the same.
from graphql-api.
Related Issues (20)
- Deriving instance FromValue - guideline for using underscore in Record field names HOT 2
- Do the warnings 'No explicit implementation for ToValue' cause errors elsewhere
- Thinking about Subscriptions HOT 1
- ValidationError VariableTypeNotFound despite presence in the schema HOT 4
- Simplify code by using DuplicateRecordFields and NamedFieldPuns HOT 3
- Refactor Value kind definition
- Simplify Value related function
- Provide a way to pass initialValue between resolver calls HOT 1
- Should graphql's selection sets be subtypes or records in haskell (as opposed to JSON-like AST) ?
- Latest release points to 0.1.1 (not 0.3.0) HOT 1
- How to construct a complex Object from Record? HOT 6
- Intergrating GraphQL and Servent Generically HOT 1
- List of Object makes an error (Tried to treat object as if it were leaf field)
- Is this project still under development ? HOT 1
- Issue with parsing non-nullable types
- Parsing documents with comments HOT 1
- How Integrate with DB provider?
- Question regarding updated features HOT 2
- Build error in `src/GraphQL/Internal/Syntax/Parser.hs`: No instance for (ConvertText Text ByteString)
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 graphql-api.