As GraphQL adoption grows, evolving API schemas without breaking existing clients becomes increasingly important. In particular, backward compatibility poses unique challenges when introducing required fields for input types and arguments. Currently, while GraphQL provides a method for deprecating fields in types and interfaces, there’s no straightforward way to signal that a field will soon become required for inputs.
To solve this, we propose the @imminent
directive—a new way to communicate upcoming changes that allows clients to prepare for new required fields before they’re enforced. Here’s how it works and why it could be a game-changer for maintaining backward compatibility in GraphQL APIs.
GraphQL schemas can be divided into inputs and outputs:
Managing backward compatibility differs for each category, especially since outputs allow more flexibility than inputs when evolving a schema. Let’s explore how these differences impact schema evolution.
When updating output fields, the process for maintaining compatibility is well-established:
When working with input fields, the situation is trickier, especially for required fields:
To address these challenges, we propose the @imminent
directive as a way to signal to clients that an optional field will soon be required. The @imminent directive allows developers to make their intentions clear, providing a transition period where clients can start including the field before it’s enforced as required.
Consider the following example:
input UpdateUserInput {
email: String
phoneNumber: String @imminent
}
In this schema, the phoneNumber
field is marked with the @imminent
directive, signaling that it will soon be mandatory. This allows developers and clients to proactively adjust their implementations, making the eventual transition to a required field smoother and less disruptive.
The @imminent
directive brings several benefits for GraphQL API management:
@imminent
fields, making it easier to stay informed of upcoming changes.The @imminent
directive provides a structured approach to schema evolution, enabling safer and more predictable changes, especially in API environments with a large client base. Here’s how it fits alongside current practices:
@imminent
allows a similar warning system for inputs.@imminent
, schema changes can be introduced gradually, giving client developers time to adapt and reducing the risk of compatibility issues.The @imminent
directive offers a promising approach for handling input field changes in GraphQL. By signaling upcoming requirements, developers can future-proof their APIs while avoiding sudden disruptions to client integrations. As the GraphQL ecosystem evolves, this directive could become a standard in schema design, providing clearer communication between API providers and consumers.
For teams looking to implement robust schema management, Inigo offers a suite of GraphQL tools to simplify compatibility checks and schema monitoring. With features like automated backward compatibility checks and schema visualization, Inigo helps ensure a stable and future-ready API. Start exploring Inigo to see how you can make schema evolution a smoother process for your team and your API consumers.