前往主要內容

graphQLMutationEffect()

底層 原子效果 用于強制對原子進行局部更新以初始化對 GraphQL 突變 到伺服器的提交。

請注意,如果原子具有多個更新其值的原子效果,則其他效果可能會導致 graphQLMutationEffect() 啟動伺服器突變。因此,如果嘗試與 graphQLQueryEffect() 結合使用,應小心。如果需要這樣做,可以使用 graphQLSelector() 替代可能會更簡單。


function graphQLMutationEffect<
TVariables: Variables,
T,
TResponse: $ReadOnly<{[string]: mixed}> = {},
TRawResponse = void,
>({
environment: IEnvironment | EnvironmentKey,
mutation: Mutation<TVariables, TResponse, TRawResponse>,
variables: T => TVariables | null,

updater_UNSTABLE?: SelectorStoreUpdater<TResponse>,
optimisticUpdater_UNSTABLE?: SelectorStoreUpdater<TResponse>,
optimisticResponse_UNSTABLE?: T => TResponse,
uploadables_UNSTABLE?: UploadableMap,
}): AtomEffect<T>
  • environment:Relay 環境或 EnvironmentKey,用以搭配 <RecoilRelayEnvironemnt> 所提供的環境。
  • mutationGraphQL 突變
  • variables:傳回變數物件的 callback,此物件會提供作為 GraphQL 突變輸入的新原子值。如果傳回 null,則略過突變。

選用選項

  • updater_UNSTABLE:傳遞給 commitMutation() 的選用 updater() 函式。
  • optimisticUpdater_UNSTABLE: 傳遞給 commitMutation() 的選用 optimisticUpdater() 函式。
  • optimisticResponse_UNSTABLE: 傳遞給 commitMutation() 的選用樂觀回應。
  • uploadables_UNSTABLE: 傳遞給 commitMutation() 的選用 uploadables