Is adding an Enum value a change for GraphQL?

According to Optimize GraphQL , a GraphQL service should follow "good practice to always avoid breaking changes and serving an idle API."

Does it add an Enum value seen as a violation that should be avoided if best practices are followed?

To illustrate this, let's say that a schema has this enum:

enum Episode {
  NEWHOPE
  EMPIRE
  JEDI
}

      

Is it bad practice to evolve enumeration in the future in the future:

enum Episode {
  NEWHOPE
  EMPIRE
  JEDI
  FORCEAWAKENS
  ROGUEONE
}

      

+3


source to share


1 answer


In particular, breaking changes are changes to the schema structure that can lead to the failure of already written queries. I couldn't find an exhaustive list online, but here are some examples of the violation:

  • Removing a field from an object type (requests that used this field have become invalid)
  • Adding a required argument to a field (requests that used a field without this argument will become invalid)
  • Changing the type of the returned field, when the new type is not a supertype of the old type (e.g. from Int

    before String

    ), clients who have used this field may have type errors from the new answer).


It is possible that the new enum value might break the client (if it didn't have the code to handle the new case, it might have a runtime error), but I think it's a client design problem, but not a violation to the schema!

+2


source







All Articles