How many GraphQL mutations does it take to change a light bulb?

It all depends on whether or not you treat this operation as an atomic one. While GraphQL specification doesn’t have any specific restrictions on that, one thing is clear: if you don’t want to have ‘no bulb’ as valid state, you should only use one mutation – in your case, changeLightBulb().

Also note that it’s quite all right to have both addLightBulb, removeLightBulb, and changeLightBulb in your set of mutations. While you might attempt to reuse domain-specific types as much as possible (then again, there are certain caveats for reusing generic fragments, covered well enough in this article), reusing the operations just to minimize the code surface is, in general, not a good idea.

Read more here: Source link