Skip to content

Commit

Permalink
compiles with rescript@next (11-rc4)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMoutonNoble committed Oct 12, 2023
1 parent f13c180 commit 95f3c46
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 74 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"devDependencies": {
"@apollo/client": "^3.5.0",
"@reasonml-community/graphql-ppx": "^1.0.0",
"@rescript/react": "~0.11.0",
"rescript": "~10.1.2",
"@rescript/react": "next",
"rescript": "next",
"graphql": "^14.0.0",
"jest": "26.5.3",
"react": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ module ApolloCache = {
(),
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let readQuery = (
Expand Down Expand Up @@ -230,7 +230,7 @@ module ApolloCache = {
~optimistic,
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let writeFragment = (
Expand Down Expand Up @@ -328,7 +328,7 @@ module ApolloCache = {
->Js.Nullable.fromOption
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let updateFragment = (
Expand Down Expand Up @@ -363,7 +363,7 @@ module ApolloCache = {
->Js.Nullable.fromOption
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

preserveJsPropsAndContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module FieldMergeFunction = {
type t<'existing> = ('existing, 'existing, FieldFunctionOptions.Js_.t) => 'existing
}

let toJs: t<'existing> => Js_.t<'existing> = (t, existing, incoming, jsFieldFunctionOptions) =>
let toJs: t<'existing> => Js_.t<'existing> = (t) =>(existing, incoming, jsFieldFunctionOptions) =>
t(existing, incoming, jsFieldFunctionOptions->FieldFunctionOptions.fromJs)
}

Expand Down Expand Up @@ -144,7 +144,7 @@ module FieldReadFunction = {
type t<'existing> = (option<'existing>, FieldFunctionOptions.Js_.t) => 'existing
}

let toJs: t<'existing> => Js_.t<'existing> = (t, existing, jsFieldFunctionOptions) =>
let toJs: t<'existing> => Js_.t<'existing> = (t) => (existing, jsFieldFunctionOptions) =>
t(existing, jsFieldFunctionOptions->FieldFunctionOptions.fromJs)
}

Expand Down
21 changes: 11 additions & 10 deletions src/@apollo/client/core/ApolloClient__Core_ApolloClient.res
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,13 @@ module Js_ = {
) => Js.Promise.t<FetchResult.Js_.t<'jsData>> = "mutate"

// onClearStore(cb: () => Promise<any>): () => void;
// TODO: named arguments to binding? - AxM
@send
external onClearStore: (t, ~cb: unit => Js.Promise.t<unit>, unit) => unit = "onClearStore"
external onClearStore: (t, ~cb: unit => Js.Promise.t<unit>) => ((unit) => unit) = "onClearStore"

// onResetStore(cb: () => Promise<any>): () => void;
@send
external onResetStore: (t, ~cb: unit => Js.Promise.t<unit>, unit) => unit = "onResetStore"
external onResetStore: (t, ~cb: unit => Js.Promise.t<unit>) => ((unit) => unit) = "onResetStore"

// query<T = any, TVariables = OperationVariables>(options: QueryOptions<TVariables>): Promise<ApolloQueryResult<T>>;
@send
Expand Down Expand Up @@ -436,9 +437,9 @@ type t = {
'variables,
) => Js.Promise.t<Belt.Result.t<FetchResult.t__ok<'data>, ApolloError.t>>,
@as("rescript_onClearStore")
onClearStore: (~cb: unit => Js.Promise.t<unit>, unit) => unit,
onClearStore: (~cb: unit => Js.Promise.t<unit>) => ((unit) => unit),
@as("rescript_onResetStore")
onResetStore: (~cb: unit => Js.Promise.t<unit>, unit) => unit,
onResetStore: (~cb: unit => Js.Promise.t<unit>) => ((unit) => unit),
@as("rescript_query")
query: 'data 'variables 'jsVariables. (
~query: module(Operation with
Expand Down Expand Up @@ -698,9 +699,9 @@ let make: (
, _)
}

let onClearStore = (~cb) => jsClient->Js_.onClearStore(~cb)
let onClearStore = (~cb): ((unit) => unit) => jsClient->Js_.onClearStore(~cb)

let onResetStore = (~cb) => jsClient->Js_.onResetStore(~cb)
let onResetStore = (~cb): ((unit) => unit) => jsClient->Js_.onResetStore(~cb)

let query = (
type data variables jsVariables,
Expand Down Expand Up @@ -777,7 +778,7 @@ let make: (
(),
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let readQuery = (
Expand Down Expand Up @@ -811,7 +812,7 @@ let make: (
~optimistic,
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let resetStore: unit => Js.Promise.t<
Expand Down Expand Up @@ -1013,7 +1014,7 @@ let make: (
->Js.Nullable.fromOption
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let updateFragment = (
Expand Down Expand Up @@ -1048,7 +1049,7 @@ let make: (
->Js.Nullable.fromOption
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

preserveJsPropsAndContext(
Expand Down
2 changes: 1 addition & 1 deletion src/@apollo/client/core/ApolloClient__Core_Types.res
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module MutationQueryReducersMap = {
~safeParse,
) =>
Js.Dict.map(
(. mutationQueryReducer) => mutationQueryReducer->MutationQueryReducer.toJs(~safeParse),
(. mutationQueryReducer) => mutationQueryReducer->MutationQueryReducer.toJs(~safeParse, ...),
t,
)
}
Expand Down
34 changes: 20 additions & 14 deletions src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ module UpdateQueryFn = {
~querySafeParse,
~querySerialize,
~subscriptionSafeParse,
. jsQueryData,
{subscriptionData: {data}},
) =>
) => ( jsQueryData, {subscriptionData: {data}}) =>
switch (jsQueryData->querySafeParse, data->subscriptionSafeParse) {
| (Ok(queryData), Ok(subscriptionData)) =>
t(
Expand Down Expand Up @@ -265,6 +263,7 @@ module SubscribeToMoreOptions = {
variables: t.variables,
updateQuery: t.updateQuery->Belt.Option.map(
UpdateQueryFn.toJs(
_,
~onParseError=onUpdateQueryParseError,
~querySafeParse,
~querySerialize,
Expand Down Expand Up @@ -323,12 +322,10 @@ module MutationUpdaterFn = {

type t<'data> = (ApolloCache.t<Js.Json.t>, FetchResult.t<'data>) => unit

let toJs: (t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>) => Js_.t<'jsData> = (
mutationUpdaterFn,
~safeParse,
. cache,
jsFetchResult,
) => mutationUpdaterFn(cache, jsFetchResult->FetchResult.fromJs(~safeParse))
let toJs: (t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>) => Js_.t<'jsData> =
(mutationUpdaterFn, ~safeParse) =>
(cache, jsFetchResult) =>
mutationUpdaterFn(cache, jsFetchResult->FetchResult.fromJs(_, ~safeParse))
}

module RefetchQueryDescription = {
Expand Down Expand Up @@ -418,12 +415,21 @@ module MutationOptions = {
errorPolicy: t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs),
fetchPolicy: t.fetchPolicy->Belt.Option.map(FetchPolicy__noCacheExtracted.toJs),
mutation: t.mutation,
optimisticResponse: t.optimisticResponse->Belt.Option.map((optimisticResponse, . variables) =>
optimisticResponse(variables)->serialize
),
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)),
updateQueries: t.updateQueries->Belt.Option.map(MutationQueryReducersMap.toJs(~safeParse)),
update: t.update->Belt.Option.map(MutationUpdaterFn.toJs(_, ~safeParse)),
updateQueries: t.updateQueries->Belt.Option.map(MutationQueryReducersMap.toJs(_, ~safeParse)),
variables: t.variables->serializeVariables->mapJsVariables,
}
}

// Option.map(arr => arr->Js.Array2.map(item => item + 1))
// let mapItem = arr => arr->Js.Array2.map(item => item + 1)
// Option.map(mapItem)
// let mapItem2 = Js.Array2.map(_, item => item + 1)
// Option.map(mapItem2)
// Option.map(Js.Array2.map(_, item => item + 1))


Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ module RequestHandler = {
module Js_ = {
// export declare type RequestHandler = (operation: Operation, forward: NextLink) => Observable<FetchResult> | null;
type t = (
. Operation.Js_.t,
Operation.Js_.t,
NextLink.Js_.t,
) => Js.Null.t<Observable.t<FetchResult.Js_.t<Js.Json.t>, Js.Exn.t>>
}
Expand All @@ -180,5 +180,5 @@ module RequestHandler = {
NextLink.Js_.t,
) => option<Observable.t<FetchResult.Js_.t<Js.Json.t>, Js.Exn.t>>

let toJs: t => Js_.t = (t, . operation, forward) => t(operation, forward)->Js.Null.fromOption
let toJs: t => Js_.t = (t) => (operation, forward) => t(operation, forward)->Js.Null.fromOption
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module DelayFunction = {

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 @@ -10,7 +10,7 @@ module RetryFunction = {

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
51 changes: 17 additions & 34 deletions src/@apollo/client/react/types/ApolloClient__React_Types.res
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,8 @@ module QueryHookOptions = {
~context=?t.context,
~displayName=?t.displayName,
~errorPolicy=?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs),
~onCompleted=?t.onCompleted->Belt.Option.map((onCompleted, jsData) =>
onCompleted(jsData->safeParse)
),
~onError=?t.onError->Belt.Option.map((onError, . jsApolloError) =>
onError(ApolloError.fromJs(jsApolloError))
),
~onCompleted=?t.onCompleted->Belt.Option.map((onCompleted) =>(jsData) => onCompleted(jsData->safeParse)),
~onError=?t.onError->Belt.Option.map((onError) =>(jsApolloError) => onError(ApolloError.fromJs(jsApolloError))),
~fetchPolicy=?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs),
~nextFetchPolicy=?t.nextFetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs),
~notifyOnNetworkStatusChange=?t.notifyOnNetworkStatusChange,
Expand Down Expand Up @@ -167,12 +163,10 @@ module LazyQueryHookOptions = {
~context=?t.context,
~displayName=?t.displayName,
~errorPolicy=?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs),
~onCompleted=?t.onCompleted->Belt.Option.map((onCompleted, jsData) =>
~onCompleted=?t.onCompleted->Belt.Option.map((onCompleted) => (jsData) =>
onCompleted(jsData->safeParse)
),
~onError=?t.onError->Belt.Option.map((onError, . jsApolloError) =>
onError(ApolloError.fromJs(jsApolloError))
),
~onError=?t.onError->Belt.Option.map((onError) => (jsApolloError) => onError(ApolloError.fromJs(jsApolloError))),
~fetchPolicy=?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs),
~notifyOnNetworkStatusChange=?t.notifyOnNetworkStatusChange,
~query=?t.query,
Expand Down Expand Up @@ -369,7 +363,7 @@ module QueryResult = {
safeParse,
)

let previousData = js.previousData->Belt.Option.map(safeParse)
let previousData = js.previousData->Belt.Option.mapU(safeParse)

let fetchMore = (
~context=?,
Expand All @@ -384,14 +378,13 @@ module QueryResult = {
->Js_.fetchMore(
Js_.t_fetchMoreOptions(
~context?,
~updateQuery=?updateQuery->Belt.Option.map((
updateQuery,
. previousResult,
~updateQuery=?updateQuery->Belt.Option.map((updateQuery) => (
previousResult,
jsFetchMoreOptions: Js_.t_fetchMoreOptions_updateQueryOptions<'jsData, 'jsVariables>,
) =>
switch (
safeParse(previousResult),
jsFetchMoreOptions.fetchMoreResult->Belt.Option.map(safeParse),
jsFetchMoreOptions.fetchMoreResult->Belt.Option.mapU(safeParse),
) {
| (Ok(previousResult), Some(Ok(fetchMoreResult))) =>
updateQuery(
Expand Down Expand Up @@ -485,7 +478,7 @@ module QueryResult = {
document: Operation.query,
variables: variables,
updateQuery: updateQuery,
onError: onError->Belt.Option.map((onError, error) =>
onError: onError->Belt.Option.map((onError) => (error) =>
onError(SubscriptionError(error))
),
context: context,
Expand Down Expand Up @@ -813,17 +806,13 @@ module MutationHookOptions = {
~ignoreResults=?t.ignoreResults,
~mutation=?t.mutation,
~notifyOnNetworkStatusChange=?t.notifyOnNetworkStatusChange,
~onError=?t.onError->Belt.Option.map((onError, . jsApolloError) =>
~onError=?t.onError->Belt.Option.map((onError) => (jsApolloError) =>
onError(ApolloError.fromJs(jsApolloError))
),
~onCompleted=?t.onCompleted->Belt.Option.map((onCompleted, jsData) =>
onCompleted(jsData->safeParse)
),
~optimisticResponse=?t.optimisticResponse->Belt.Option.map((optimisticResponse, variables) =>
optimisticResponse(variables)->serialize
),
~onCompleted=?t.onCompleted->Belt.Option.map((onCompleted) =>(jsData) => onCompleted(jsData->safeParse)),
~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)),
~update=?t.update->Belt.Option.map(MutationUpdaterFn.toJs(_, ~safeParse)),
~variables=?t.variables->Belt.Option.map(v => v->serializeVariables->mapJsVariables),
(),
)
Expand Down Expand Up @@ -925,12 +914,12 @@ module MutationFunctionOptions = {
~serializeVariables,
) => {
variables: t.variables->serializeVariables->mapJsVariables,
optimisticResponse: t.optimisticResponse->Belt.Option.map((optimisticResponse, . variables) =>
optimisticResponse: t.optimisticResponse->Belt.Option.map((optimisticResponse) => (variables) =>
optimisticResponse(variables)->serialize
),
refetchQueries: t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs),
awaitRefetchQueries: t.awaitRefetchQueries,
update: t.update->Belt.Option.map(MutationUpdaterFn.toJs(~safeParse)),
update: t.update->Belt.Option.map(MutationUpdaterFn.toJs(_, ~safeParse)),
context: t.context,
fetchPolicy: t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs),
}
Expand Down Expand Up @@ -1247,16 +1236,10 @@ module SubscriptionHookOptions = {
~subscription=?t.subscription,
~variables=t.variables->serializeVariables->mapJsVariables,
~fetchPolicy=?t.fetchPolicy,
~shouldResubscribe=?t.shouldResubscribe->Belt.Option.map((
shouldResubscribe,
. jsBaseSubscriptionOptions,
) => shouldResubscribe(jsBaseSubscriptionOptions->BaseSubscriptionOptions.fromJs)),
~shouldResubscribe=?t.shouldResubscribe->Belt.Option.map((shouldResubscribe) => (jsBaseSubscriptionOptions) => shouldResubscribe(jsBaseSubscriptionOptions->BaseSubscriptionOptions.fromJs)),
~client=?t.client,
~skip=?t.skip,
~onSubscriptionData=?t.onSubscriptionData->Belt.Option.map((
onSubscriptionData,
. jsOnSubscriptionDataOptions,
) =>
~onSubscriptionData=?t.onSubscriptionData->Belt.Option.map((onSubscriptionData) => (jsOnSubscriptionDataOptions) =>
onSubscriptionData(
jsOnSubscriptionDataOptions->OnSubscriptionDataOptions.fromJs(~safeParse),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ let make = (
),
)

React.useEffect0(() => {
React.useEffect(() => {
Some(client.current.stop)
})
}, [])

<ApolloProvider client=client.current>
{React.cloneElement(
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: error})
Expand Down

0 comments on commit 95f3c46

Please sign in to comment.