Relay: Feature: shared object between mutation and network

Created on 18 Jul 2019  路  7Comments  路  Source: facebook/relay

I wanted to propose the addition of an optional parameter in commitMutation shared with the network interface, in order to allow add extra information during the execution of the mutation.

This parameter will be very useful in offline contexts, but I think it is also useful for other use cases.

wontfix

Most helpful comment

Yeah, totally reasonable to add CacheConfig as an optional arg to those methods. For executeMutation it鈥檚 a bit awkward though bc force:false doesn鈥檛 make sense.

All 7 comments

Can鈥檛 you use updater?

No, because that function is not used by the network.

https://github.com/facebook/relay/blob/master/packages/relay-runtime/store/RelayModernEnvironment.js#L327

perhaps an example makes it clearer:

as is

const source = this._network.execute (
         operation.node.params,
         operation.variables,
         {force: true},
         uploadables,
       );

to be

const source = this._network.execute (
         operation.node.params,
         operation.variables,
         {force: true},
         uploadables,
         extra
       );

This is what what CacheConfig (the third {force:true} arg in your example) is intended for. There's an optional metadata property that can be any object w whatever info you need.

Great news, my problem is solved :) maybe it could be useful to add this property in commitMutation too:

commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    extra
})

and to modify RelayModernEnvironment to use it as you suggested:

https://github.com/facebook/relay/blob/master/packages/relay-runtime/store/RelayModernEnvironment.js#L330

{force: true, metadata: extra }

what do you think?

Yeah, totally reasonable to add CacheConfig as an optional arg to those methods. For executeMutation it鈥檚 a bit awkward though bc force:false doesn鈥檛 make sense.

Perhaps it is sufficient to create a subtype with a different name :)

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fedbalves picture fedbalves  路  3Comments

HsuTing picture HsuTing  路  3Comments

janicduplessis picture janicduplessis  路  3Comments

johntran picture johntran  路  3Comments

bondanherumurti picture bondanherumurti  路  3Comments