Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
zatchheems committed Jan 7, 2025
1 parent 2c33012 commit 0a85fb9
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 95 deletions.
11 changes: 5 additions & 6 deletions src/@apollo/client/core/ApolloClient__Core_Types.res
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@ module MutationQueryReducer = {
let toJs: (
t<'data>,
~safeParse: Types.safeParse<'data, 'jsData>,
) => (Js.Json.t, Js_.options<'jsData>) => Js.Json.t = (t, ~safeParse) => (
previousResult,
jsOptions,
) =>
Js.Json.t,
Js_.options<'jsData>,
) => Js.Json.t = (t, ~safeParse, previousResult, jsOptions) =>
t(
previousResult,
{
Expand All @@ -179,8 +178,8 @@ module MutationQueryReducersMap = {
let toJs: (t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>) => Js_.t<'jsData> = (
t,
~safeParse,
) => Js.Dict.map((. mutationQueryReducer) => {
(json, options) => mutationQueryReducer->MutationQueryReducer.toJs(~safeParse, json, options)
) => Js.Dict.map(mutationQueryReducer => {
(json, options) => MutationQueryReducer.toJs(mutationQueryReducer, ~safeParse, json, options)
}, t)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ module MutationOptions = {
mutation: t.mutation,
optimisticResponse: ?t.optimisticResponse->Belt.Option.map(optimisticResponse => variables =>
optimisticResponse(variables)->serialize),
refetchQueries: t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs),
update: t.update->Belt.Option.map(MutationUpdaterFn.toJs(_, ~safeParse)),
refetchQueries: ?t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs),
update: ?t.update->Belt.Option.map(MutationUpdaterFn.toJs(_, ~safeParse)),
updateQueries: ?t.updateQueries->Belt.Option.map(MutationQueryReducersMap.toJs(_, ~safeParse)),
variables: t.variables->serializeVariables->mapJsVariables,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module DelayFunction = {
// export interface DelayFunction {
// (count: number, operation: Operation, error: any): number;
// }
type t = (. int, Operation.Js_.t, option<Js.Json.t>) => int
type t = (int, Operation.Js_.t, option<Js.Json.t>) => int
}

type t = (~count: int, ~operation: Operation.t, ~error: option<Js.Json.t>) => int

let toJs: t => Js_.t = (t, count, operation, error) =>
let toJs: t => Js_.t = t => (count, operation, error) =>
t(~count, ~operation=operation->Operation.fromJs, ~error)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module RetryFunction = {
// export interface RetryFunction {
// (count: number, operation: Operation, error: any): boolean | Promise<boolean>;
// }
type t = (. int, Operation.Js_.t, option<Js.Json.t>) => Js.Promise.t<bool>
type t = (int, Operation.Js_.t, option<Js.Json.t>) => Js.Promise.t<bool>
}

type t = (~count: int, ~operation: Operation.t, ~error: option<Js.Json.t>) => Js.Promise.t<bool>

let toJs: t => Js_.t = (t, count, operation, error) =>
let toJs: t => Js_.t = t => (count, operation, error) =>
t(~count, ~operation=operation->Operation.fromJs, ~error)
}

Expand Down
151 changes: 69 additions & 82 deletions src/@apollo/client/react/types/ApolloClient__React_Types.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module QueryHookOptions = {
// ...extends QueryFunctionOptions
displayName?: string,
skip?: bool,
onCompleted?: (. 'jsData) => unit,
onError?: (. ApolloError.Js_.t) => unit,
onCompleted?: 'jsData => unit,
onError?: ApolloError.Js_.t => unit,
// ..extends BaseQueryOptions
client?: ApolloClient.t,
context?: Js.Json.t, // ACTUAL: Record<string, any>
Expand Down Expand Up @@ -78,12 +78,10 @@ module QueryHookOptions = {
context: ?t.context,
displayName: ?t.displayName,
errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs),
onCompleted: ?t.onCompleted->Belt.Option.map(onCompleted =>
jsData => jsData->safeParse->onCompleted
),
onError: ?t.onError->Belt.Option.mapU(onError =>
jsApolloError => jsApolloError->ApolloError.fromJs->onError
),
onCompleted: ?t.onCompleted->Belt.Option.map(onCompleted => jsData =>
jsData->safeParse->onCompleted),
onError: ?t.onError->Belt.Option.mapU(onError => jsApolloError =>
jsApolloError->ApolloError.fromJs->onError),
fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs),
nextFetchPolicy: ?t.nextFetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs),
notifyOnNetworkStatusChange: ?t.notifyOnNetworkStatusChange,
Expand Down Expand Up @@ -154,12 +152,10 @@ module LazyQueryHookOptions = {
context: ?t.context,
displayName: ?t.displayName,
errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs),
onCompleted: ?t.onCompleted->Belt.Option.mapU((. onCompleted) =>
jsData => safeParse(. jsData)->onCompleted
),
onError: ?t.onError->Belt.Option.mapU(onError =>
jsApolloError => ApolloError.fromJs(jsApolloError)->onError
),
onCompleted: ?t.onCompleted->Belt.Option.mapU(onCompleted => jsData =>
safeParse(jsData)->onCompleted),
onError: ?t.onError->Belt.Option.mapU(onError => jsApolloError =>
ApolloError.fromJs(jsApolloError)->onError),
fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(WatchQueryFetchPolicy.toJs),
notifyOnNetworkStatusChange: ?t.notifyOnNetworkStatusChange,
query: ?t.query,
Expand Down Expand Up @@ -205,7 +201,7 @@ module QueryResult = {
context?: Js.Json.t,
// ...extends FetchMoreOptions
updateQuery?: (
. 'jsData,
'jsData,
t_fetchMoreOptions_updateQueryOptions<'jsData, 'jsVariables>,
) => 'jsData,
}
Expand Down Expand Up @@ -367,40 +363,38 @@ module QueryResult = {
js
->Js_.fetchMore({
?context,
updateQuery: ?updateQuery->Belt.Option.mapU((. updateQuery) =>
(.
previousResult,
jsFetchMoreOptions: Js_.t_fetchMoreOptions_updateQueryOptions<'jsData, 'jsVariables>,
) =>
switch (
safeParse(previousResult),
jsFetchMoreOptions.fetchMoreResult->Belt.Option.map(safeParse(_)),
) {
| (Ok(previousResult), Some(Ok(fetchMoreResult))) =>
updateQuery(
previousResult,
{
fetchMoreResult: Some(fetchMoreResult),
variables: jsFetchMoreOptions.variables,
},
)->serialize
| (Ok(previousResult), None) =>
updateQuery(
previousResult,
{
fetchMoreResult: None,
variables: jsFetchMoreOptions.variables,
},
)->serialize
| (Error(parseError), _)
| (Ok(_), Some(Error(parseError))) =>
parseErrorDuringCall.contents = Some(Error(parseError))
previousResult
}
),
variables: ?variables->Belt.Option.mapU((. v) => v->serializeVariables->mapJsVariables),
updateQuery: ?updateQuery->Belt.Option.mapU(updateQuery => (
previousResult,
jsFetchMoreOptions: Js_.t_fetchMoreOptions_updateQueryOptions<'jsData, 'jsVariables>,
) =>
switch (
safeParse(previousResult),
jsFetchMoreOptions.fetchMoreResult->Belt.Option.map(safeParse(_)),
) {
| (Ok(previousResult), Some(Ok(fetchMoreResult))) =>
updateQuery(
previousResult,
{
fetchMoreResult: Some(fetchMoreResult),
variables: jsFetchMoreOptions.variables,
},
)->serialize
| (Ok(previousResult), None) =>
updateQuery(
previousResult,
{
fetchMoreResult: None,
variables: jsFetchMoreOptions.variables,
},
)->serialize
| (Error(parseError), _)
| (Ok(_), Some(Error(parseError))) =>
parseErrorDuringCall.contents = Some(Error(parseError))
previousResult
}),
variables: ?variables->Belt.Option.mapU(v => v->serializeVariables->mapJsVariables),
})
->Js.Promise.then_(jsApolloQueryResult =>
->(Js.Promise.then_(jsApolloQueryResult =>
Js.Promise.resolve(
switch parseErrorDuringCall.contents {
| Some(Error(parseError)) =>
Expand All @@ -427,8 +421,8 @@ module QueryResult = {

let refetch = (~mapJsVariables=Utils.identity, ~variables=?, ()) =>
js
->Js_.refetch(variables->Belt.Option.mapU((. v) => v->serializeVariables->mapJsVariables))
->Js.Promise.then_(
->Js_.refetch(variables->Belt.Option.mapU(v => v->serializeVariables->mapJsVariables))
->(Js.Promise.then_(
jsApolloQueryResult =>
Js.Promise.resolve(
jsApolloQueryResult->ApolloQueryResult.fromJs(~safeParse)->ApolloQueryResult.toResult,
Expand Down Expand Up @@ -462,7 +456,7 @@ module QueryResult = {
~context=?,
variables,
) => {
let subscriptionSafeParse = Utils.safeParse(. Operation.parse)
let subscriptionSafeParse = Utils.safeParse(Operation.parse)

js->Js_.subscribeToMore(
SubscribeToMoreOptions.toJs(
Expand Down Expand Up @@ -490,7 +484,7 @@ module QueryResult = {

let updateQuery = updateQueryFn =>
js->Js_.updateQuery((jsPreviousData, options) =>
updateQueryFn(safeParse(. jsPreviousData), options)->serialize
updateQueryFn(safeParse(jsPreviousData), options)->serialize
)

{
Expand Down Expand Up @@ -705,7 +699,7 @@ module BaseMutationOptions = {
notifyOnNetworkStatusChange: option<bool>,
onError: option<ApolloError.Js_.t => unit>,
onCompleted: 'jsData => unit,
optimisticResponse: option<(. 'jsVariables) => 'jsData>,
optimisticResponse: option<'jsVariables => 'jsData>,
refetchQueries: option<RefetchQueryDescription.Js_.t>,
update: option<MutationUpdaterFn.Js_.t<'jsData>>,
variables: option<'jsVariables>,
Expand Down Expand Up @@ -744,8 +738,8 @@ module MutationHookOptions = {
fetchPolicy?: FetchPolicy__noCacheExtracted.Js_.t,
ignoreResults?: bool,
notifyOnNetworkStatusChange?: bool,
onError?: (. ApolloError.Js_.t) => unit,
onCompleted?: (. 'jsData) => unit,
onError?: ApolloError.Js_.t => unit,
onCompleted?: 'jsData => unit,
optimisticResponse?: 'jsVariables => 'jsData,
refetchQueries?: RefetchQueryDescription.Js_.t,
update?: MutationUpdaterFn.Js_.t<'jsData>,
Expand Down Expand Up @@ -791,21 +785,17 @@ module MutationHookOptions = {
ignoreResults: ?t.ignoreResults,
mutation: ?t.mutation,
notifyOnNetworkStatusChange: ?t.notifyOnNetworkStatusChange,
onError: ?t.onError->Belt.Option.mapU((. onError) =>
(. jsApolloError) => onError(ApolloError.fromJs(. jsApolloError))
),
onCompleted: ?t.onCompleted->Belt.Option.mapU((. onCompleted) =>
(. jsData) => safeParse(. jsData)->onCompleted
),
onError: ?t.onError->Belt.Option.mapU(onError => jsApolloError =>
onError(ApolloError.fromJs(jsApolloError))),
onCompleted: ?t.onCompleted->Belt.Option.mapU(onCompleted => jsData =>
safeParse(jsData)->onCompleted),
optimisticResponse: ?switch t.optimisticResponse {
| None => None
| Some(optimisticResponse) => Some(variables => optimisticResponse(variables)->serialize)
},
refetchQueries: ?t.refetchQueries->Belt.Option.mapU(RefetchQueryDescription.toJs),
update: ?t.update->Belt.Option.mapU((. updater) =>
MutationUpdaterFn.toJs(. updater, ~safeParse)
),
variables: ?t.variables->Belt.Option.mapU((. v) => v->serializeVariables->mapJsVariables),
update: ?t.update->Belt.Option.mapU(updater => MutationUpdaterFn.toJs(updater, ~safeParse)),
variables: ?t.variables->Belt.Option.mapU(v => v->serializeVariables->mapJsVariables),
}
}

Expand Down Expand Up @@ -872,7 +862,7 @@ module MutationFunctionOptions = {
type t<'jsData, 'jsVariables> = {
// We don't allow optional variables because it's not typesafe
variables: 'jsVariables,
optimisticResponse?: (. 'jsVariables) => 'jsData,
optimisticResponse?: 'jsVariables => 'jsData,
refetchQueries?: RefetchQueryDescription.Js_.t,
awaitRefetchQueries?: bool,
update?: MutationUpdaterFn.Js_.t<'jsData>,
Expand Down Expand Up @@ -905,14 +895,11 @@ module MutationFunctionOptions = {
~serializeVariables,
) => {
variables: t.variables->serializeVariables->mapJsVariables,
optimisticResponse: ?t.optimisticResponse->Belt.Option.mapU((. optimisticResponse) =>
(. variables) => optimisticResponse(variables)->serialize
),
optimisticResponse: ?t.optimisticResponse->Belt.Option.mapU(optimisticResponse => variables =>
optimisticResponse(variables)->serialize),
refetchQueries: ?t.refetchQueries->Belt.Option.mapU(RefetchQueryDescription.toJs),
awaitRefetchQueries: ?t.awaitRefetchQueries,
update: ?t.update->Belt.Option.mapU((. updater) =>
MutationUpdaterFn.toJs(. updater, ~safeParse)
),
update: ?t.update->Belt.Option.mapU(updater => MutationUpdaterFn.toJs(updater, ~safeParse)),
context: ?t.context,
fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(WatchQueryFetchPolicy.toJs),
}
Expand Down Expand Up @@ -1161,10 +1148,10 @@ module BaseSubscriptionOptions = {
type rec t<'jsData, 'jsVariables> = {
variables?: 'jsVariables,
fetchPolicy?: FetchPolicy.t,
shouldResubscribe?: (. t<'jsData, 'jsVariables>) => bool,
shouldResubscribe?: t<'jsData, 'jsVariables> => bool,
client?: ApolloClient.t,
skip?: bool,
onSubscriptionData?: (. OnSubscriptionDataOptions.Js_.t<'jsData>) => unit,
onSubscriptionData?: OnSubscriptionDataOptions.Js_.t<'jsData> => unit,
onSubscriptionComplete?: unit => unit,
}
}
Expand Down Expand Up @@ -1203,10 +1190,10 @@ module SubscriptionHookOptions = {
// Intentionally restricted to not be non-optional. `option(unit)` does not compile cleanly to `undefined`
variables: 'jsVariables,
fetchPolicy?: FetchPolicy.Js_.t,
shouldResubscribe?: (. BaseSubscriptionOptions.Js_.t<'jsData, 'jsVariables>) => bool,
shouldResubscribe?: BaseSubscriptionOptions.Js_.t<'jsData, 'jsVariables> => bool,
client?: ApolloClient.t,
skip?: bool,
onSubscriptionData?: (. OnSubscriptionDataOptions.Js_.t<'jsData>) => unit,
onSubscriptionData?: OnSubscriptionDataOptions.Js_.t<'jsData> => unit,
onSubscriptionComplete?: unit => unit,
}
}
Expand All @@ -1231,17 +1218,17 @@ module SubscriptionHookOptions = {
subscription: ?t.subscription,
variables: t.variables->serializeVariables->mapJsVariables,
fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(FetchPolicy.toJs),
shouldResubscribe: ?t.shouldResubscribe->Belt.Option.mapU((. shouldResubscribe) =>
(. jsBaseSubscriptionOptions) =>
shouldResubscribe(jsBaseSubscriptionOptions->BaseSubscriptionOptions.fromJs)
shouldResubscribe: ?t.shouldResubscribe->Belt.Option.mapU(
shouldResubscribe => jsBaseSubscriptionOptions =>
shouldResubscribe(jsBaseSubscriptionOptions->BaseSubscriptionOptions.fromJs),
),
client: ?t.client,
skip: ?t.skip,
onSubscriptionData: ?t.onSubscriptionData->Belt.Option.mapU((. onSubscriptionData) =>
(. jsOnSubscriptionDataOptions) =>
onSubscriptionData: ?t.onSubscriptionData->Belt.Option.mapU(
onSubscriptionData => jsOnSubscriptionDataOptions =>
onSubscriptionData(
jsOnSubscriptionDataOptions->OnSubscriptionDataOptions.fromJs(~safeParse),
)
),
),
onSubscriptionComplete: ?t.onSubscriptionComplete,
}
Expand Down
2 changes: 1 addition & 1 deletion src/ApolloClient__Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let ensureError = ApolloError.ensureError

external asJson: 'any => Js.Json.t = "%identity"

let safeParse: ('jsData => 'data) => Types.safeParse<'data, 'jsData> = (parse, jsData) =>
let safeParse: ('jsData => 'data) => Types.safeParse<'data, 'jsData> = parse => jsData =>
switch parse(jsData) {
| data => Ok(data)
| exception Js.Exn.Error(error) => Error({value: jsData->asJson, error})
Expand Down

0 comments on commit 0a85fb9

Please sign in to comment.