Relay: Mutations do not generate covariant/read only flow types

Created on 30 Nov 2018  路  4Comments  路  Source: facebook/relay

Read queries generate flow types which are covariant/read-only. This makes sense: bad stuff starts to happen when you mutate objects that exist in the relay store!

However, mutations generate input types which seem somewhat inconsistent. Concretely, they use $ReadOnlyArray, but object properties are not marked as covariant.

This is somewhat inconvenient, because there are a number of cases where some or all of a mutation input may be very similar or even identical in shape to the result of a query. It would be nice to be able to define fewer types, but additionally it is not uncommon that one may ultimately want to pass the result of a GraphQL query through to a mutation. This typing prevents that.

Additionally, the typing here causes issues when providing objects with non-null properties to a mutation which accepts those properties as null. For instance, given a mutation which takes an input object typed as { foo: ?string }, providing an object typed as { foo: string } will cause a type error. But if the input object is typed {+foo: ?string}, this is no longer an issue.

My guess is that relay does not actually mutate the input objects it receives. If that's true, would it be possible to update the typing here to use covariant properties and encode that guarantee of non-mutation in the typing?

Most helpful comment

This continues to cause heartache and deep existential dread.

All 4 comments

cc @kassens is this just an oversight?

This continues to cause heartache and deep existential dread.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

bump

Was this page helpful?
0 / 5 - 0 ratings