Skip to content

Instantly share code, notes, and snippets.

@renanmav
Created May 15, 2020 14:43
Show Gist options
  • Save renanmav/651a93661660e80544ed191617ddb1b8 to your computer and use it in GitHub Desktop.
Save renanmav/651a93661660e80544ed191617ddb1b8 to your computer and use it in GitHub Desktop.
My changes to remove the option of response within onCompleted on the commitMutation function
We've found a bug for you!
/Users/renan/git/reason-relay/packages/reason-relay/src/ReasonRelay.re 1201:31-49
1199 ┆ switch (optimisticResponse) {
1200 ┆ | None => None
1201 ┆ | Some(r) => Some(r |> C.wrapResponse)
1202 ┆ },
1203 ┆ optimisticUpdater,
This has type:
C.responseRaw
But somewhere wanted:
Js.Nullable.t(C.responseRaw) (defined as Js.nullable(C.responseRaw))
FAILED: subcommand failed.
type _commitMutationConfig('variables, 'response) = {
mutation: mutationNode,
variables: 'variables,
onCompleted:
option(('response, Js.Nullable.t(array(mutationError))) => unit),
onError: option(Js.Nullable.t(mutationError) => unit),
optimisticResponse: option('response),
optimisticUpdater: option(optimisticUpdaterFn),
updater: option(updaterFn('response)),
};
module MakeCommitMutation = (C: MutationConfig) => {
let commitMutation =
(
~environment: Environment.t,
~variables: C.variables,
~optimisticUpdater=?,
~optimisticResponse=?,
~updater=?,
~onCompleted=?,
~onError=?,
(),
)
: Disposable.t =>
_commitMutation(
environment,
{
variables: variables |> C.convertVariables |> _cleanVariables,
mutation: C.node,
onCompleted:
Some(
(res, err) =>
switch (onCompleted) {
| Some(cb) =>
cb(res->C.convertResponse, Js.Nullable.toOption(err))
| None => ()
},
),
onError:
Some(
err =>
switch (onError) {
| Some(cb) => cb(Js.Nullable.toOption(err))
| None => ()
},
),
optimisticResponse:
switch (optimisticResponse) {
| None => None
| Some(r) => Some(r |> C.wrapResponse)
},
optimisticUpdater,
updater:
switch (updater) {
| None => None
| Some(updater) =>
Some((store, r) => updater(store, r |> C.convertResponse))
},
},
);
let commitMutationPromised =
(
~environment: Environment.t,
~variables: C.variables,
~optimisticUpdater=?,
~optimisticResponse=?,
~updater=?,
(),
)
: Promise.t(
Belt.Result.t(
(option(C.response), option(array(mutationError))),
option(mutationError),
),
) => {
let (promise, resolve) = Promise.pending();
let _: Disposable.t =
_commitMutation(
environment,
{
variables: variables |> C.convertVariables |> _cleanVariables,
mutation: C.node,
onCompleted:
Some(
(res, err) =>
resolve(
Ok((
switch (Js.Nullable.toOption(res)) {
| Some(res) => Some(res->C.convertResponse)
| None => None
},
Js.Nullable.toOption(err),
)),
),
),
onError: Some(err => resolve(Error(Js.Nullable.toOption(err)))),
optimisticResponse:
switch (optimisticResponse) {
| None => None
| Some(r) => Some(r |> C.wrapResponse)
},
optimisticUpdater,
updater:
switch (updater) {
| None => None
| Some(updater) =>
Some((store, r) => updater(store, r |> C.convertResponse))
},
},
);
promise;
};
};
module MakeCommitMutation:
(C: MutationConfig) =>
{
let commitMutation:
(
~environment: Environment.t,
~variables: C.variables,
~optimisticUpdater: optimisticUpdaterFn=?,
~optimisticResponse: C.response=?,
~updater: (RecordSourceSelectorProxy.t, C.response) => unit=?,
~onCompleted: (C.response, option(array(mutationError))) =>
unit
=?,
~onError: option(mutationError) => unit=?,
unit
) =>
Disposable.t;
let commitMutationPromised:
(
~environment: Environment.t,
~variables: C.variables,
~optimisticUpdater: optimisticUpdaterFn=?,
~optimisticResponse: C.response=?,
~updater: (RecordSourceSelectorProxy.t, C.response) => unit=?,
unit
) =>
Promise.t(
Belt.Result.t(
(option(C.response), option(array(mutationError))),
option(mutationError),
),
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment