Add '@ignoreIfUnknown' to allow forward compatibility for clients
At a glance​
- Identifier: #319
- Stage: RFCX: Closed 2018-10-02T03:54:29Z
- Champion: @IvanGoncharov
- PR: Add '@ignoreIfUnknown' to allow forward compatibility for clients
Timeline​
- Mentioned in 2020-02-06 WG notes
- Spec PR created on 2017-06-13 by IvanGoncharov
- Commit pushed: Add '@ignoreIfUnknown' to allow forward compatibility for clients on 2017-06-13 by @IvanGoncharov
GraphQL is an excellent technology for backward compatibility of APIs. However, sometimes you need to provide forward compatibility for the clients.
The big example is introspection mechanism of GraphQL itself. Up to this moment, there were two changes in it:
onOperation
,onFragment
andonField
fields were deprecated in favor oflocations
- new
subscriptionType
field was addedIn both cases, backward compatibility was preserved, so old clients can still work with newer GraphQL APIs. However, forward compatibility is broken since you can't use the same introspection query for both old and new servers. For example, GraphiQL solves this by having fallback query without
subscriptionType
field: https://github.com/graphql/graphiql/blob/master/src/utility/introspectionQueries.js#L11-L13This problem is even trickier since GraphQL libraries for many languages (including
graphql-js
) expose standard introspection query. Should this "standard" query incorporate features from the last standard or should it stick to the query supported by the first public release of GraphQL?To address forward compatibility I propose to add
@ignoreIfUnknown
directive that will silently ignore fields that weren't defined inside appropriate type. Comparing toskip
/include
it will not only omit value from response but also prevent the query failing during validation.This issue is not only limited to introspection. I think this feature can solve similar problems for IoT (different firmware versions), distributed systems, etc.