According to the GraphQL Best Practices, a GraphQL service should follow the "common practice of always avoiding breaking changes and serving a versionless API."
Is adding a value to an Enum considered a breaking change that should be avoided if following the Best Practices?
To illustrate this, let's say that the schema has this enum:
enum Episode {
NEWHOPE
EMPIRE
JEDI
}
Is it bad practice to evolve the enum to be this sometime in the future:
enum Episode {
NEWHOPE
EMPIRE
JEDI
FORCEAWAKENS
ROGUEONE
}
Specifically, breaking changes are changes to schema structure that would cause already-written queries to fail. I couldn't find an exhaustive list online, but here are few example breaking changes:
Int
to String
, clients which used that field may have type errors from the new response).It's possible that a new enum value could break a client (if it didn't have code to handle the new case, it may have a runtime error), but I think that's a client design issue, but not a breaking change to the schema!
TLDR: Adding a value to an enum is considered a "potentially dangerous change".
According to the spec (http://spec.graphql.org/October2021/#sec-Validation.Type-system-evolution)
Any change that can cause a previously valid request to become invalid is considered a breaking change.
I tried to find a definitive list of breaking changes and it was more difficult than I expected. It appears that there is both a concept of "breaking changes" and of "dangerous changes" in graphql-js cooresponding to two functions findBreakingChanges
and findDangerousChanges
. findDangerousChanges
was recommended to be added by this PR: https://github.com/graphql/graphql-js/pull/701#issuecomment-277851631 because while some changes don't meet the definition of "breaking" according the the spec they are still "potentially dangerous". According the code adding a value to an enum is considered a "potentially dangerous change":
https://github.com/graphql/graphql-js/blob/40ff40a21c710372330e65f0fb58f13c2df92a77/src/utilities/findBreakingChanges.ts#L37-L63
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With