Giter Site home page Giter Site logo

Domain errors on Mutations about graphql-api HOT 1 OPEN

thiagorp avatar thiagorp commented on August 16, 2024 1
Domain errors on Mutations

from graphql-api.

Comments (1)

certainty avatar certainty commented on August 16, 2024 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:

  1. if the mutation failed with a domain error you want to stop execution at that level
  2. you likely want typed errors
  3. 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)

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.