diff --git a/package.json b/package.json index 9dcaf73..6b05610 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res b/src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res index cd97cb9..14dd4cf 100644 --- a/src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res +++ b/src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res @@ -196,7 +196,7 @@ module ApolloCache = { (), ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let readQuery = ( @@ -230,7 +230,7 @@ module ApolloCache = { ~optimistic, ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let writeFragment = ( @@ -328,7 +328,7 @@ module ApolloCache = { ->Js.Nullable.fromOption ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let updateFragment = ( @@ -363,7 +363,7 @@ module ApolloCache = { ->Js.Nullable.fromOption ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } preserveJsPropsAndContext( diff --git a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies_FieldPolicy.res b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies_FieldPolicy.res index 5fe0bde..ab335a4 100644 --- a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies_FieldPolicy.res +++ b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies_FieldPolicy.res @@ -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) } @@ -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) } diff --git a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res index 40059f5..64356da 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res +++ b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res @@ -317,12 +317,13 @@ module Js_ = { ) => Js.Promise.t> = "mutate" // onClearStore(cb: () => Promise): () => void; + // TODO: named arguments to binding? - AxM @send - external onClearStore: (t, ~cb: unit => Js.Promise.t, unit) => unit = "onClearStore" + external onClearStore: (t, ~cb: unit => Js.Promise.t) => ((unit) => unit) = "onClearStore" // onResetStore(cb: () => Promise): () => void; @send - external onResetStore: (t, ~cb: unit => Js.Promise.t, unit) => unit = "onResetStore" + external onResetStore: (t, ~cb: unit => Js.Promise.t) => ((unit) => unit) = "onResetStore" // query(options: QueryOptions): Promise>; @send @@ -436,9 +437,9 @@ type t = { 'variables, ) => Js.Promise.t, ApolloError.t>>, @as("rescript_onClearStore") - onClearStore: (~cb: unit => Js.Promise.t, unit) => unit, + onClearStore: (~cb: unit => Js.Promise.t) => ((unit) => unit), @as("rescript_onResetStore") - onResetStore: (~cb: unit => Js.Promise.t, unit) => unit, + onResetStore: (~cb: unit => Js.Promise.t) => ((unit) => unit), @as("rescript_query") query: 'data 'variables 'jsVariables. ( ~query: module(Operation with @@ -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, @@ -777,7 +778,7 @@ let make: ( (), ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let readQuery = ( @@ -811,7 +812,7 @@ let make: ( ~optimistic, ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let resetStore: unit => Js.Promise.t< @@ -1013,7 +1014,7 @@ let make: ( ->Js.Nullable.fromOption ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let updateFragment = ( @@ -1048,7 +1049,7 @@ let make: ( ->Js.Nullable.fromOption ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } preserveJsPropsAndContext( diff --git a/src/@apollo/client/core/ApolloClient__Core_Types.res b/src/@apollo/client/core/ApolloClient__Core_Types.res index b3152a8..d4ab1bf 100644 --- a/src/@apollo/client/core/ApolloClient__Core_Types.res +++ b/src/@apollo/client/core/ApolloClient__Core_Types.res @@ -180,7 +180,7 @@ module MutationQueryReducersMap = { ~safeParse, ) => Js.Dict.map( - (. mutationQueryReducer) => mutationQueryReducer->MutationQueryReducer.toJs(~safeParse), + (. mutationQueryReducer) => mutationQueryReducer->MutationQueryReducer.toJs(~safeParse, ...), t, ) } diff --git a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res index 7ac57ea..34983ed 100644 --- a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res +++ b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res @@ -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( @@ -265,6 +263,7 @@ module SubscribeToMoreOptions = { variables: t.variables, updateQuery: t.updateQuery->Belt.Option.map( UpdateQueryFn.toJs( + _, ~onParseError=onUpdateQueryParseError, ~querySafeParse, ~querySerialize, @@ -323,12 +322,10 @@ module MutationUpdaterFn = { type t<'data> = (ApolloCache.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 = { @@ -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)) + + diff --git a/src/@apollo/client/link/core/ApolloClient__Link_Core_Types.res b/src/@apollo/client/link/core/ApolloClient__Link_Core_Types.res index ce23ea6..8fa14a6 100644 --- a/src/@apollo/client/link/core/ApolloClient__Link_Core_Types.res +++ b/src/@apollo/client/link/core/ApolloClient__Link_Core_Types.res @@ -169,7 +169,7 @@ module RequestHandler = { module Js_ = { // export declare type RequestHandler = (operation: Operation, forward: NextLink) => Observable | null; type t = ( - . Operation.Js_.t, + Operation.Js_.t, NextLink.Js_.t, ) => Js.Null.t, Js.Exn.t>> } @@ -180,5 +180,5 @@ module RequestHandler = { NextLink.Js_.t, ) => option, 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 } diff --git a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_DelayFunction.res b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_DelayFunction.res index a7abe44..c83c590 100644 --- a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_DelayFunction.res +++ b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_DelayFunction.res @@ -10,7 +10,7 @@ module DelayFunction = { type t = (~count: int, ~operation: Operation.t, ~error: option) => 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) } diff --git a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryFunction.res b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryFunction.res index a6763a2..4f1a650 100644 --- a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryFunction.res +++ b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryFunction.res @@ -10,7 +10,7 @@ module RetryFunction = { type t = (~count: int, ~operation: Operation.t, ~error: option) => Js.Promise.t - 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) } diff --git a/src/@apollo/client/react/types/ApolloClient__React_Types.res b/src/@apollo/client/react/types/ApolloClient__React_Types.res index d70f775..4faedcf 100644 --- a/src/@apollo/client/react/types/ApolloClient__React_Types.res +++ b/src/@apollo/client/react/types/ApolloClient__React_Types.res @@ -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, @@ -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, @@ -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=?, @@ -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( @@ -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, @@ -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), (), ) @@ -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), } @@ -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), ) diff --git a/src/@apollo/client/testing/react/ApolloClient__Testing_React_MockedProvider.res b/src/@apollo/client/testing/react/ApolloClient__Testing_React_MockedProvider.res index cdcf08a..280ff93 100644 --- a/src/@apollo/client/testing/react/ApolloClient__Testing_React_MockedProvider.res +++ b/src/@apollo/client/testing/react/ApolloClient__Testing_React_MockedProvider.res @@ -40,9 +40,9 @@ let make = ( ), ) - React.useEffect0(() => { + React.useEffect(() => { Some(client.current.stop) - }) + }, []) {React.cloneElement( diff --git a/src/ApolloClient__Utils.res b/src/ApolloClient__Utils.res index 56f620f..55d3a54 100644 --- a/src/ApolloClient__Utils.res +++ b/src/ApolloClient__Utils.res @@ -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})