Khan / Khan/genqlient

Supporting backward compatible schemas

Open
#386 4 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
Go
Stars
1.3k
Forks
143
Avg merge
4h 50m
Merged PRs (30d)
1

Description

**Is your feature request related to a problem? Please describe.**
When making changes over time to a GraphQL schema, one of them might be adding a new type to an interface.
According to the GraphQL spec this is not considered a breaking change (see https://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.

As only a new type was added, all previous queries will still work.
`graphql-js` in turn "only" registers this as a "potentially dangerous change" (see https://github.com/graphql/graphql-js/blob/bb87e73067865207e19924297cabff45686f2a76/src/utilities/findBreakingChanges.ts#L62).

This all brings me to the conclusion that adding a new type to an existing interface should work also for `genqlient`.

**Describe the solution you'd like**
It would be great to allow the deserialization of responses using unknown types.
That could be achieved by using a default struct that just implements the common values of the interface and that is used as a fallback in case the type is unknown.
Optionally this behavior could be enabled/disabled depending on the use-case of the implementation.

**Describe alternatives you've considered**
The only other option would be to force people updating their applications which may become impossible/very cumbersome if there are a large number of service affected.

**Additional context**
None

Contributor guide

Open the contributing guide

Research direction

Start with the GraphQL type-system evolution section linked in the issue and graphql-js's findBreakingChanges.ts reference, then trace genqlient's response deserialization and interface handling. Done means responses containing newly added, previously unknown interface types can be deserialized without breaking existing clients, with the requested control over fallback behavior defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, graphql
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.