Replies: 1 comment 7 replies
-
From my experience, it's unusual in GraphQL to have the whole endpoint versioned. Instead, I recommend continuously updating a single schema. This is also mentioned on the GraphQL website:
Naturally, adding new types or fields is a non-breaking change in GraphQL. To deprecate old fields/types, you can use the Have you considered this approach, or is versioning the endpoint the only option in your case? |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to be able to make breaking changes to my GraphQL API. I am doing this by creating different schemas and exposing them at
/graphql/v1
,/graphql/v2
etc.Most changes are relatively minor and implemented by subclassing the latest schema and overwriting a single mutator or changing a field. Earlier versions are implemented by subclassing the next version, leading to a chain of schemas all the way to the latest one. The latest schema is the "main" one, containing most of the logic, so that earlier versions can be deprecated and deleted. This isn't pretty, but it works. The code is open source, for example: https://github.com/magenta-aps/os2mo/blob/1f557a658145200e090c4805eb8fe24df6761bc1/backend/mora/graphapi/versions/v21/version.py.
Sometimes, subclassing the schema doesn't cut it. For example, if I need to change a field on a type which is used both directly in the top-level query as well as nested as fields on other types. In this case, I can overwrite the field and type on the top-level query easily, but I also have to overwrite in any fields which reference it, and then any fields which reference those models. The number of required changes quickly explodes.
Is there a better way to do this? Does the schema have a store of all types which I could use to overwrite one type with another everywhere in the schema at once?
EDIT: Subclassing is a bad idea. Please see my reply about GraphQL Ruby's Changesets.
Beta Was this translation helpful? Give feedback.
All reactions