From 6e92f9b5ffb44da21f1669c7e76789164e7c9c9e Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 28 Sep 2023 23:51:51 -0400 Subject: [PATCH 01/16] refactor: convert @obj and @deriving(abstract) to use optional record fields --- ...loClient__Cache_InMemory_InMemoryCache.res | 35 +- .../ApolloClient__Cache_InMemory_Policies.res | 32 +- .../ApolloClient__Core_WatchQueryOptions.res | 79 ++-- .../ApolloClient__Errors_ApolloError.res | 10 +- .../react/types/ApolloClient__React_Types.res | 404 ++++++++---------- 5 files changed, 248 insertions(+), 312 deletions(-) diff --git a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_InMemoryCache.res b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_InMemoryCache.res index dab15c7..4fbd480 100644 --- a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_InMemoryCache.res +++ b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_InMemoryCache.res @@ -11,24 +11,16 @@ module InMemoryCacheConfig = { // possibleTypes?: PossibleTypesMap; // typePolicies?: TypePolicies; // } - // NOTE: Using deriving abstract here because passing properties that are undefined has effects - @deriving(abstract) type t = { - @optional - resultCaching: bool, - @optional - possibleTypes: PossibleTypesMap.Js_.t, - @optional - typePolicies: TypePolicies.Js_.t, + resultCaching?: bool, + possibleTypes?: PossibleTypesMap.Js_.t, + typePolicies?: TypePolicies.Js_.t, // ...extends ApolloReducerConfig - @optional - dataIdFromObject: KeyFieldsFunction.Js_.t, - @optional - addTypename: bool, + dataIdFromObject?: KeyFieldsFunction.Js_.t, + addTypename?: bool, } } type t = Js_.t - let make = Js_.t } module Js_ = { @@ -88,13 +80,10 @@ let make: ( ~typePolicies=?, (), ) => - Js_.make( - InMemoryCacheConfig.make( - ~addTypename?, - ~dataIdFromObject?, - ~possibleTypes?, - ~resultCaching?, - ~typePolicies=?typePolicies->Belt.Option.map(TypePolicies.toJs), - (), - ), - )->ApolloCache.fromJs + Js_.make({ + ?addTypename, + ?dataIdFromObject, + ?possibleTypes, + ?resultCaching, + typePolicies: ?typePolicies->Belt.Option.map(TypePolicies.toJs), + })->ApolloCache.fromJs diff --git a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res index fd5bfe2..768d6fe 100644 --- a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res +++ b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res @@ -9,24 +9,10 @@ module SelectionSetNode = ApolloClient__Graphql.Language.Ast.SelectionSetNode module KeyFieldsContext = { type t = { - typename: option, - selectionSet: option, - fragment: option, - keyObject: option, - } - module Js_ = { - // declare type KeyFieldsContext = { - // typename?: string; - // selectionSet?: SelectionSetNode; - // fragmentMap?: FragmentMap; - // keyObject?: Record; - // }; - type t = t = { - typename: option, - selectionSet: option, - fragment: option, - keyObject: option, - } + typename?: string, + selectionSet?: SelectionSetNode.t, + fragment?: FragmentMap.t, + keyObject?: Js.Json.t, } } @@ -126,11 +112,11 @@ module TypePolicy = { ~subscriptionType: bool=?, unit, ) => t = (~fields=?, ~keyFields=?, ~mutationType=?, ~queryType=?, ~subscriptionType=?, ()) => { - fields: fields, - keyFields: keyFields, - mutationType: mutationType, - queryType: queryType, - subscriptionType: subscriptionType, + fields, + keyFields, + mutationType, + queryType, + subscriptionType, } } diff --git a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res index 7ac57ea..0ed6ecf 100644 --- a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res +++ b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res @@ -8,7 +8,7 @@ module PureQueryOptions = ApolloClient__Core_Types.PureQueryOptions module ErrorPolicy = { module Js_ = { // export declare type ErrorPolicy = 'none' | 'ignore' | 'all'; - type t = string + type t = [#none | #ignore | #all] } type t = @@ -18,16 +18,16 @@ module ErrorPolicy = { let toJs = x => switch x { - | None => "none" - | Ignore => "ignore" - | All => "all" + | None => #none + | Ignore => #ignore + | All => #all } } module FetchPolicy = { module Js_ = { // export declare type FetchPolicy = 'cache-first' | 'network-only' | 'cache-only' | 'no-cache' | 'standby'; - type t = string + type t = [#"cache-first" | #"network-only" | #"cache-only" | #"no-cache" | #standby] } type t = @@ -37,13 +37,13 @@ module FetchPolicy = { | NoCache | Standby - let toJs = x => + let toJs = (x): Js_.t => switch x { - | CacheFirst => "cache-first" - | CacheOnly => "cache-only" - | NetworkOnly => "network-only" - | NoCache => "no-cache" - | Standby => "standby" + | CacheFirst => #"cache-first" + | CacheOnly => #"cache-only" + | NetworkOnly => #"network-only" + | NoCache => #"no-cache" + | Standby => #standby } } @@ -63,7 +63,7 @@ module FetchPolicy__noCacheExtracted = { module WatchQueryFetchPolicy = { module Js_ = { // export declare type WatchQueryFetchPolicy = FetchPolicy | 'cache-and-network'; - type t = string + type t = [FetchPolicy.Js_.t | #"cache-and-network"] } type t = @@ -74,14 +74,14 @@ module WatchQueryFetchPolicy = { | NoCache | Standby - let toJs = x => + let toJs = (x): Js_.t => switch x { - | CacheAndNetwork => "cache-and-network" - | CacheFirst => "cache-first" - | CacheOnly => "cache-only" - | NetworkOnly => "network-only" - | NoCache => "no-cache" - | Standby => "standby" + | CacheAndNetwork => #"cache-and-network" + | CacheFirst => #"cache-first" + | CacheOnly => #"cache-only" + | NetworkOnly => #"network-only" + | NoCache => #"no-cache" + | Standby => #standby } } @@ -198,24 +198,23 @@ module UpdateQueryFn = { ~querySafeParse, ~querySerialize, ~subscriptionSafeParse, - . jsQueryData, - {subscriptionData: {data}}, ) => - switch (jsQueryData->querySafeParse, data->subscriptionSafeParse) { - | (Ok(queryData), Ok(subscriptionData)) => - t( - queryData, - { - subscriptionData: { - data: subscriptionData, + (. jsQueryData, {subscriptionData: {data}}) => + switch (jsQueryData->querySafeParse, data->subscriptionSafeParse) { + | (Ok(queryData), Ok(subscriptionData)) => + t( + queryData, + { + subscriptionData: { + data: subscriptionData, + }, }, - }, - )->querySerialize - | (Error(parseError), _) - | (_, Error(parseError)) => - onParseError(parseError) - jsQueryData - } + )->querySerialize + | (Error(parseError), _) + | (_, Error(parseError)) => + onParseError(parseError) + jsQueryData + } } module SubscribeToMoreOptions = { @@ -326,9 +325,9 @@ module MutationUpdaterFn = { let toJs: (t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>) => Js_.t<'jsData> = ( mutationUpdaterFn, ~safeParse, - . cache, - jsFetchResult, - ) => mutationUpdaterFn(cache, jsFetchResult->FetchResult.fromJs(~safeParse)) + ) => + (. cache, jsFetchResult) => + mutationUpdaterFn(cache, jsFetchResult->FetchResult.fromJs(~safeParse)) } module RefetchQueryDescription = { @@ -418,8 +417,8 @@ 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)), diff --git a/src/@apollo/client/errors/ApolloClient__Errors_ApolloError.res b/src/@apollo/client/errors/ApolloClient__Errors_ApolloError.res index 477bd02..bf84102 100644 --- a/src/@apollo/client/errors/ApolloClient__Errors_ApolloError.res +++ b/src/@apollo/client/errors/ApolloClient__Errors_ApolloError.res @@ -108,7 +108,7 @@ module Js_ = { } else if (error && typeof error.message === "string" && error.extensions) { return makeApolloError({graphQLErrors: [error]}); } else { - return makeApolloError({networkError: ensureError(error)}) + return makeApolloError({networkError: ensureError(error)}) } } `)(error, make, ensureError) @@ -161,11 +161,11 @@ let make: ( unit, ) => t = (~graphQLErrors=?, ~networkError=?, ~errorMessage=?, ~extraInfo=?, ()) => { let errorWithoutNetworkError = Js_.make({ - graphQLErrors: graphQLErrors, + graphQLErrors, networkError: Js.Nullable.undefined, - errorMessage: errorMessage, - extraInfo: extraInfo, + errorMessage, + extraInfo, })->fromJs - {...errorWithoutNetworkError, networkError: networkError} + {...errorWithoutNetworkError, networkError} } diff --git a/src/@apollo/client/react/types/ApolloClient__React_Types.res b/src/@apollo/client/react/types/ApolloClient__React_Types.res index d70f775..6db080b 100644 --- a/src/@apollo/client/react/types/ApolloClient__React_Types.res +++ b/src/@apollo/client/react/types/ApolloClient__React_Types.res @@ -22,33 +22,28 @@ module QueryHookOptions = { // export interface QueryHookOptions extends QueryFunctionOptions { // query?: DocumentNode; // } - type t<'jsData, 'jsVariables> - - // NOTE: We are using @obj here because passing properties that are defined with a value of undefined has effects - @obj - external make: ( - ~query: Graphql.documentNode=?, + type t<'jsData, 'jsVariables> = { + query?: Graphql.documentNode, // ...extends QueryFunctionOptions - ~displayName: string=?, - ~skip: bool=?, - ~onCompleted: 'jsData => unit=?, - ~onError: (. ApolloError.Js_.t) => unit=?, + displayName?: string, + skip?: bool, + onCompleted?: 'jsData => unit, + onError?: (. ApolloError.Js_.t) => unit, // ..extends BaseQueryOptions - ~client: ApolloClient.t=?, - ~context: Js.Json.t=?, // ACTUAL: Record - ~errorPolicy: string=?, - ~fetchPolicy: string=?, - ~nextFetchPolicy: string=?, - ~notifyOnNetworkStatusChange: bool=?, - ~partialRefetch: bool=?, - ~pollInterval: int=?, + client?: ApolloClient.t, + context?: Js.Json.t, // ACTUAL: Record + errorPolicy?: ErrorPolicy.Js_.t, + fetchPolicy?: WatchQueryFetchPolicy.Js_.t, + nextFetchPolicy?: WatchQueryFetchPolicy.Js_.t, + notifyOnNetworkStatusChange?: bool, + partialRefetch?: bool, + pollInterval?: int, // INTENTIONALLY IGNORED (but now with safeParse and result unwrapping, maybe it shouldn't be?) - // ~returnPartialData: bool=?, - ~ssr: bool=?, + // returnPartialData?: bool, + ssr?: bool, // We don't allow optional variables because it's not typesafe - ~variables: 'jsVariables, - unit, - ) => t<'jsData, 'jsVariables> = "" + variables: 'jsVariables, + } } type t<'data, 'variables> = { @@ -78,29 +73,27 @@ module QueryHookOptions = { ~mapJsVariables: 'jsVariables => 'jsVariables, ~safeParse: Types.safeParse<'data, 'jsData>, ~serializeVariables: 'variables => 'jsVariables, - ): Js_.t<'jsData, 'jsVariables> => - Js_.make( - ~client=?t.client, - ~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)) - ), - ~fetchPolicy=?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), - ~nextFetchPolicy=?t.nextFetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), - ~notifyOnNetworkStatusChange=?t.notifyOnNetworkStatusChange, - ~query=?t.query, - ~pollInterval=?t.pollInterval, - ~partialRefetch=?t.partialRefetch, - ~skip=?t.skip, - ~ssr=?t.ssr, - ~variables=t.variables->serializeVariables->mapJsVariables, - (), - ) + ): Js_.t<'jsData, 'jsVariables> => { + client: ?t.client, + 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.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, + query: ?t.query, + pollInterval: ?t.pollInterval, + partialRefetch: ?t.partialRefetch, + skip: ?t.skip, + ssr: ?t.ssr, + variables: t.variables->serializeVariables->mapJsVariables, + } } module LazyQueryHookOptions = { @@ -109,31 +102,26 @@ module LazyQueryHookOptions = { // query?: DocumentNode; // } - type t<'jsData, 'jsVariables> - - // NOTE: We are using @obj here because passing properties that are defined with a value of undefined has effects - @obj - external make: ( - ~query: Graphql.documentNode=?, + type t<'jsData, 'jsVariables> = { + query?: Graphql.documentNode, // ...extends QueryFunctionOptions - ~displayName: string=?, - ~onCompleted: 'jsData => unit=?, - ~onError: (. ApolloError.Js_.t) => unit=?, + displayName?: string, + onCompleted?: 'jsData => unit, + onError?: (. ApolloError.Js_.t) => unit, // ..extends BaseQueryOptions - ~client: ApolloClient.t=?, - ~context: Js.Json.t=?, // ACTUAL: Record, - ~errorPolicy: string=?, - ~fetchPolicy: string=?, - ~nextFetchPolicy: string=?, - ~notifyOnNetworkStatusChange: bool=?, - ~partialRefetch: bool=?, - ~pollInterval: int=?, + client?: ApolloClient.t, + context?: Js.Json.t, // ACTUAL: Record, + errorPolicy?: ErrorPolicy.Js_.t, + fetchPolicy?: WatchQueryFetchPolicy.Js_.t, + nextFetchPolicy?: WatchQueryFetchPolicy.Js_.t, + notifyOnNetworkStatusChange?: bool, + partialRefetch?: bool, + pollInterval?: int, // INTENTIONALLY IGNORED (but now with safeParse and result unwrapping, maybe it shouldn't be?) - // ~returnPartialData:bool=?, - ~ssr: bool=?, - ~variables: 'jsVariables=?, - unit, - ) => t<'jsData, 'jsVariables> = "" + // returnPartialData?: bool, + ssr?: bool, + variables?: 'jsVariables, + } } type t<'data, 'variables> = { @@ -161,28 +149,27 @@ module LazyQueryHookOptions = { t: t<'data, 'variables>, ~safeParse: Types.safeParse<'data, 'jsData>, ~serializeVariables: 'variables => 'jsVariables, - ): Js_.t<'jsData, 'jsVariables> => - Js_.make( - ~client=?t.client, - ~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)) - ), - ~fetchPolicy=?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), - ~notifyOnNetworkStatusChange=?t.notifyOnNetworkStatusChange, - ~query=?t.query, - ~pollInterval=?t.pollInterval, - ~partialRefetch=?t.partialRefetch, - ~ssr=?t.ssr, - ~variables=?t.variables->Belt.Option.map(serializeVariables), - (), - ) + ): Js_.t<'jsData, 'jsVariables> => { + client: ?t.client, + 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)) + ), + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), + notifyOnNetworkStatusChange: ?t.notifyOnNetworkStatusChange, + query: ?t.query, + pollInterval: ?t.pollInterval, + partialRefetch: ?t.partialRefetch, + ssr: ?t.ssr, + variables: ?t.variables->Belt.Option.map(serializeVariables), + } } + module QueryLazyOptions = { module Js_ = { // export interface QueryLazyOptions { @@ -208,19 +195,13 @@ module QueryResult = { variables: option<'jsVariables>, } - // We use abstract because Apollo is looking at query key, not just value - @deriving(abstract) type t_fetchMoreOptions<'jsData, 'jsVariables> = { - @optional - query: Graphql.Language.documentNode, + query?: Graphql.Language.documentNode, // ...extends FetchMoreQueryOptions - @optional - variables: 'jsVariables, - @optional - context: Js.Json.t, + variables?: 'jsVariables, + context?: Js.Json.t, // ...extends FetchMoreOptions - @optional - updateQuery: ( + updateQuery?: ( . 'jsData, t_fetchMoreOptions_updateQueryOptions<'jsData, 'jsVariables>, ) => 'jsData, @@ -381,12 +362,11 @@ module QueryResult = { let parseErrorDuringCall: ref>> = ref(None) js - ->Js_.fetchMore( - Js_.t_fetchMoreOptions( - ~context?, - ~updateQuery=?updateQuery->Belt.Option.map(( - updateQuery, - . previousResult, + ->Js_.fetchMore({ + ?context, + updateQuery: ?updateQuery->Belt.Option.map(updateQuery => + (. + previousResult, jsFetchMoreOptions: Js_.t_fetchMoreOptions_updateQueryOptions<'jsData, 'jsVariables>, ) => switch ( @@ -414,11 +394,9 @@ module QueryResult = { parseErrorDuringCall.contents = Some(Error(parseError)) previousResult } - ), - ~variables=?variables->Belt.Option.map(v => v->serializeVariables->mapJsVariables), - (), ), - ) + variables: ?variables->Belt.Option.map(v => v->serializeVariables->mapJsVariables), + }) ->Js.Promise.then_(jsApolloQueryResult => Js.Promise.resolve( switch parseErrorDuringCall.contents { @@ -483,12 +461,12 @@ module QueryResult = { SubscribeToMoreOptions.toJs( { document: Operation.query, - variables: variables, - updateQuery: updateQuery, + variables, + updateQuery, onError: onError->Belt.Option.map((onError, error) => onError(SubscriptionError(error)) ), - context: context, + context, }, ~onUpdateQueryParseError=parseError => switch onError { @@ -510,17 +488,17 @@ module QueryResult = { { called: js.called, client: js.client, - data: data, - previousData: previousData, - error: error, + data, + previousData, + error, loading: js.loading, networkStatus: js.networkStatus->NetworkStatus.fromJs, - fetchMore: fetchMore, - refetch: refetch, - startPolling: startPolling, - stopPolling: stopPolling, - subscribeToMore: subscribeToMore, - updateQuery: updateQuery, + fetchMore, + refetch, + startPolling, + stopPolling, + subscribeToMore, + updateQuery, } } } @@ -636,7 +614,7 @@ module QueryTuple = { ) => ( (~context=?, ~mapJsVariables=ApolloClient__Utils.identity, variables) => jsExecuteQuery({ - context: context, + context, variables: variables->serializeVariables->mapJsVariables, }) |> Js.Promise.then_(jsResult => QueryResult.fromJs( @@ -680,7 +658,7 @@ module QueryTuple__noVariables = { ) => ( (~context=?, ()) => jsExecuteQuery({ - context: context, + context, variables: variables->serializeVariables->mapJsVariables, }) |> Js.Promise.then_(jsResult => QueryResult.fromJs( @@ -750,28 +728,23 @@ module MutationHookOptions = { // export interface MutationHookOptions extends BaseMutationOptions { // mutation?: DocumentNode; // } - type t<'jsData, 'jsVariables> - - // NOTE: We are using @obj here because passing properties that are defined with a value of undefined has effects - @obj - external make: ( - ~mutation: Graphql.documentNode=?, + type t<'jsData, 'jsVariables> = { + mutation?: Graphql.documentNode, // ...extends BaseMutationOptions - ~awaitRefetchQueries: bool=?, - ~client: ApolloClient.t=?, // Non-Js_ client is appropriate here - ~context: Js.Json.t=?, // actual: option(Context) - ~errorPolicy: ErrorPolicy.Js_.t=?, - ~fetchPolicy: FetchPolicy__noCacheExtracted.Js_.t=?, - ~ignoreResults: bool=?, - ~notifyOnNetworkStatusChange: bool=?, - ~onError: (. ApolloError.Js_.t) => unit=?, - ~onCompleted: 'jsData => unit=?, - ~optimisticResponse: 'jsVariables => 'jsData=?, - ~refetchQueries: RefetchQueryDescription.Js_.t=?, - ~update: MutationUpdaterFn.Js_.t<'jsData>=?, - ~variables: 'jsVariables=?, - unit, - ) => t<'jsData, 'jsVariables> = "" + awaitRefetchQueries?: bool, + client?: ApolloClient.t, // Non-Js_ client is appropriate here + context?: Js.Json.t, // actual: option(Context) + errorPolicy?: ErrorPolicy.Js_.t, + fetchPolicy?: FetchPolicy__noCacheExtracted.Js_.t, + ignoreResults?: bool, + notifyOnNetworkStatusChange?: bool, + onError?: (. ApolloError.Js_.t) => unit, + onCompleted?: 'jsData => unit, + optimisticResponse?: 'jsVariables => 'jsData, + refetchQueries?: RefetchQueryDescription.Js_.t, + update?: MutationUpdaterFn.Js_.t<'jsData>, + variables?: 'jsVariables, + } } type t<'data, 'variables, 'jsVariables> = { @@ -803,30 +776,28 @@ module MutationHookOptions = { ~safeParse, ~serialize, ~serializeVariables, - ) => - Js_.make( - ~awaitRefetchQueries=?t.awaitRefetchQueries, - ~context=?t.context, - ~client=?t.client, - ~errorPolicy=?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - ~fetchPolicy=?t.fetchPolicy->Belt.Option.map(FetchPolicy__noCacheExtracted.toJs), - ~ignoreResults=?t.ignoreResults, - ~mutation=?t.mutation, - ~notifyOnNetworkStatusChange=?t.notifyOnNetworkStatusChange, - ~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 - ), - ~refetchQueries=?t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs), - ~update=?t.update->Belt.Option.map(MutationUpdaterFn.toJs(~safeParse)), - ~variables=?t.variables->Belt.Option.map(v => v->serializeVariables->mapJsVariables), - (), - ) + ) => { + awaitRefetchQueries: ?t.awaitRefetchQueries, + context: ?t.context, + client: ?t.client, + errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy__noCacheExtracted.toJs), + ignoreResults: ?t.ignoreResults, + mutation: ?t.mutation, + notifyOnNetworkStatusChange: ?t.notifyOnNetworkStatusChange, + 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 + ), + refetchQueries: ?t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs), + update: ?t.update->Belt.Option.map(MutationUpdaterFn.toJs(~safeParse)), + variables: ?t.variables->Belt.Option.map(v => v->serializeVariables->mapJsVariables), + } } module MutationResult = { @@ -868,8 +839,8 @@ module MutationResult = { safeParse, ) { - data: data, - error: error, + data, + error, loading: js.loading, called: js.called, client: js.client, @@ -925,8 +896,8 @@ module MutationFunctionOptions = { ~serializeVariables, ) => { variables: t.variables->serializeVariables->mapJsVariables, - 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), awaitRefetchQueries: t.awaitRefetchQueries, @@ -988,13 +959,13 @@ module MutationTuple = { Some( MutationFunctionOptions.toJs( { - variables: variables, - optimisticResponse: optimisticResponse, - refetchQueries: refetchQueries, - awaitRefetchQueries: awaitRefetchQueries, - update: update, - context: context, - fetchPolicy: fetchPolicy, + variables, + optimisticResponse, + refetchQueries, + awaitRefetchQueries, + update, + context, + fetchPolicy, }, ~mapJsVariables, ~safeParse, @@ -1065,13 +1036,13 @@ module MutationTuple__noVariables = { Some( MutationFunctionOptions.toJs( { - variables: variables, - optimisticResponse: optimisticResponse, - refetchQueries: refetchQueries, - awaitRefetchQueries: awaitRefetchQueries, - update: update, - context: context, - fetchPolicy: fetchPolicy, + variables, + optimisticResponse, + refetchQueries, + awaitRefetchQueries, + update, + context, + fetchPolicy, }, ~mapJsVariables, ~safeParse, @@ -1127,7 +1098,7 @@ module SubscriptionResult = { safeParse, ) - {loading: js.loading, data: data, error: error} + {loading: js.loading, data, error} } } @@ -1207,23 +1178,18 @@ module SubscriptionHookOptions = { // export interface SubscriptionHookOptions extends BaseSubscriptionOptions { // subscription?: DocumentNode; // } - type t<'jsData, 'jsVariables> - - // NOTE: We are using @obj here because passing properties that are defined with a value of undefined has effects - @obj - external make: ( - ~subscription: Graphql.documentNode=?, + type t<'jsData, 'jsVariables> = { + subscription?: Graphql.documentNode, // ...extends BaseSubscriptionOptions // Intentionally restricted to not be non-optional. `option(unit)` does not compile cleanly to `undefined` - ~variables: 'jsVariables, - ~fetchPolicy: FetchPolicy.t=?, - ~shouldResubscribe: (. BaseSubscriptionOptions.Js_.t<'jsData, 'jsVariables>) => bool=?, - ~client: ApolloClient.t=?, - ~skip: bool=?, - ~onSubscriptionData: (. OnSubscriptionDataOptions.Js_.t<'jsData>) => unit=?, - ~onSubscriptionComplete: unit => unit=?, - unit, - ) => t<'jsData, 'jsVariables> = "" + variables: 'jsVariables, + fetchPolicy?: FetchPolicy.Js_.t, + shouldResubscribe?: (. BaseSubscriptionOptions.Js_.t<'jsData, 'jsVariables>) => bool, + client?: ApolloClient.t, + skip?: bool, + onSubscriptionData?: (. OnSubscriptionDataOptions.Js_.t<'jsData>) => unit, + onSubscriptionComplete?: unit => unit, + } } type t<'data, 'variables, 'jsVariables> = { @@ -1242,26 +1208,22 @@ module SubscriptionHookOptions = { ~mapJsVariables: 'jsVariables => 'jsVariables, ~safeParse: Types.safeParse<'data, 'jsData>, ~serializeVariables: 'variables => 'jsVariables, - ) => Js_.t<'jsData, 'jsVariables> = (t, ~mapJsVariables, ~safeParse, ~serializeVariables) => - Js_.make( - ~subscription=?t.subscription, - ~variables=t.variables->serializeVariables->mapJsVariables, - ~fetchPolicy=?t.fetchPolicy, - ~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, - ) => + ) => Js_.t<'jsData, 'jsVariables> = (t, ~mapJsVariables, ~safeParse, ~serializeVariables) => { + subscription: ?t.subscription, + variables: t.variables->serializeVariables->mapJsVariables, + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), + 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( jsOnSubscriptionDataOptions->OnSubscriptionDataOptions.fromJs(~safeParse), ) - ), - ~onSubscriptionComplete=?t.onSubscriptionComplete, - (), - ) + ), + onSubscriptionComplete: ?t.onSubscriptionComplete, + } } From 6323b0e7ea70154edde2f161e5bbcb79a6355995 Mon Sep 17 00:00:00 2001 From: rob Date: Mon, 5 Feb 2024 23:17:53 -0500 Subject: [PATCH 02/16] refactor: convert ApolloClient__Core_ApolloClient.res --- .../core/ApolloClient__Core_ApolloClient.res | 438 +++++++++--------- 1 file changed, 222 insertions(+), 216 deletions(-) diff --git a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res index 40059f5..c544392 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res +++ b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res @@ -33,30 +33,30 @@ module DefaultWatchQueryOptions = { module Js_ = { // Partial; type t = { - fetchPolicy: option, + fetchPolicy?: WatchQueryFetchPolicy.Js_.t, // query: GraphQL.Language.documentNode, - // variables: option('jsVariables), - errorPolicy: option, - context: option, + // variables?: 'jsVariables, + errorPolicy?: ErrorPolicy.Js_.t, + context?: Js.Json.t, } } type t = { - fetchPolicy: option, - errorPolicy: option, - context: option, + fetchPolicy?: WatchQueryFetchPolicy.t, + errorPolicy?: ErrorPolicy.t, + context?: Js.Json.t, } let toJs: t => Js_.t = t => { - fetchPolicy: t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), - errorPolicy: t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - context: t.context, + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + context: ?t.context, } let make = (~fetchPolicy=?, ~errorPolicy=?, ~context=?, ()) => { - fetchPolicy: fetchPolicy, - errorPolicy: errorPolicy, - context: context, + ?fetchPolicy, + ?errorPolicy, + ?context, } } @@ -64,30 +64,30 @@ module DefaultQueryOptions = { module Js_ = { // Partial; type t = { - fetchPolicy: option, + fetchPolicy?: FetchPolicy.Js_.t, // query: GraphQL.Language.documentNode, - // variables: option('jsVariables), - errorPolicy: option, - context: option, + // variables?: 'jsVariables, + errorPolicy?: ErrorPolicy.Js_.t, + context?: Js.Json.t, } } type t = { - fetchPolicy: option, - errorPolicy: option, - context: option, + fetchPolicy?: FetchPolicy.t, + errorPolicy?: ErrorPolicy.t, + context?: Js.Json.t, } let toJs: t => Js_.t = t => { - fetchPolicy: t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), - errorPolicy: t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - context: t.context, + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + context: ?t.context, } let make = (~fetchPolicy=?, ~errorPolicy=?, ~context=?, ()) => { - fetchPolicy: fetchPolicy, - errorPolicy: errorPolicy, - context: context, + ?fetchPolicy, + ?errorPolicy, + ?context, } } @@ -95,34 +95,35 @@ module DefaultMutateOptions = { module Js_ = { // Partial; type t = { - context: option, - fetchPolicy: option, - awaitRefetchQueries: option, - errorPolicy: option, - // optimisticResponse: option('jsVariables => 'jsData), - // update: option(MutationUpdaterFn.Js_.t('jsData)), - // updateQueries: option(MutationQueryReducersMap.Js_.t('jsData)), - refetchQueries: option, - // variables: option('jsVariables), + context?: Js.Json.t, + fetchPolicy?: FetchPolicy__noCacheExtracted.Js_.t, + awaitRefetchQueries?: bool, + errorPolicy?: ErrorPolicy.Js_.t, + // optimisticResponse?: 'jsVariables => 'jsData, + // update?: MutationUpdaterFn.Js_.t<'jsData>, + // updateQueries?: MutationQueryReducersMap.Js_.t<'jsData>, + refetchQueries?: RefetchQueryDescription.Js_.t, + // variables?: 'jsVariables, } } type t = { - context: option, - fetchPolicy: option, - awaitRefetchQueries: option, - errorPolicy: option, - refetchQueries: option, + context?: Js.Json.t, + fetchPolicy?: FetchPolicy__noCacheExtracted.t, + awaitRefetchQueries?: bool, + errorPolicy?: ErrorPolicy.t, + refetchQueries?: RefetchQueryDescription.t, } let toJs: t => Js_.t = t => { - context: t.context, - fetchPolicy: t.fetchPolicy->Belt.Option.map(FetchPolicy__noCacheExtracted.toJs), - awaitRefetchQueries: t.awaitRefetchQueries, - errorPolicy: t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - refetchQueries: t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs), + context: ?t.context, + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy__noCacheExtracted.toJs), + awaitRefetchQueries: ?t.awaitRefetchQueries, + errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + refetchQueries: ?t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs), } + @deprecated("Just construct instead") let make = ( ~context=?, ~fetchPolicy=?, @@ -131,11 +132,11 @@ module DefaultMutateOptions = { ~refetchQueries=?, (), ) => { - context: context, - fetchPolicy: fetchPolicy, - awaitRefetchQueries: awaitRefetchQueries, - errorPolicy: errorPolicy, - refetchQueries: refetchQueries, + ?context, + ?fetchPolicy, + ?awaitRefetchQueries, + ?errorPolicy, + ?refetchQueries, } } @@ -147,33 +148,34 @@ module DefaultOptions = { // mutate?: Partial; // } type t = { - watchQuery: option, - query: option, - mutate: option, + watchQuery?: DefaultWatchQueryOptions.Js_.t, + query?: DefaultQueryOptions.Js_.t, + mutate?: DefaultMutateOptions.Js_.t, } } type t = { - watchQuery: option, - query: option, - mutate: option, + watchQuery?: DefaultWatchQueryOptions.t, + query?: DefaultQueryOptions.t, + mutate?: DefaultMutateOptions.t, } let toJs: t => Js_.t = t => { - watchQuery: t.watchQuery->Belt.Option.map(DefaultWatchQueryOptions.toJs), - query: t.query->Belt.Option.map(DefaultQueryOptions.toJs), - mutate: t.mutate->Belt.Option.map(DefaultMutateOptions.toJs), + watchQuery: ?t.watchQuery->Belt.Option.map(DefaultWatchQueryOptions.toJs), + query: ?t.query->Belt.Option.map(DefaultQueryOptions.toJs), + mutate: ?t.mutate->Belt.Option.map(DefaultMutateOptions.toJs), } + @deprecated("Just construct instead") let make: ( ~mutate: DefaultMutateOptions.t=?, ~query: DefaultQueryOptions.t=?, ~watchQuery: DefaultWatchQueryOptions.t=?, unit, ) => t = (~mutate=?, ~query=?, ~watchQuery=?, ()) => { - watchQuery: watchQuery, - query: query, - mutate: mutate, + ?watchQuery, + ?query, + ?mutate, } } @@ -198,61 +200,61 @@ module ApolloClientOptions = { // version?: string; // }; type t = { - uri: option, - credentials: option, - headers: option>, - link: option, + uri?: UriFunction.Js_.t, + credentials?: string, + headers?: Js.Dict.t, + link?: ApolloLink.Js_.t, cache: ApolloCache.t, // Non-Js_ ApolloCache is correct here - ssrForceFetchDelay: option, - ssrMode: option, - connectToDevTools: option, - queryDeduplication: option, - defaultOptions: option, - assumeImmutableResults: option, - resolvers: option>, - typeDefs: option>, - fragmentMatcher: option, - name: option, - version: option, + ssrForceFetchDelay?: int, + ssrMode?: bool, + connectToDevTools?: bool, + queryDeduplication?: bool, + defaultOptions?: DefaultOptions.Js_.t, + assumeImmutableResults?: bool, + resolvers?: array, + typeDefs?: array, + fragmentMatcher?: FragmentMatcher.Js_.t, + name?: string, + version?: string, } } type t = { - uri: option, - credentials: option, - headers: option>, - link: option, + uri?: UriFunction.t, + credentials?: string, + headers?: Js.Dict.t, + link?: ApolloLink.t, cache: ApolloCache.t, - ssrForceFetchDelay: option, - ssrMode: option, - connectToDevTools: option, - queryDeduplication: option, - defaultOptions: option, - assumeImmutableResults: option, - resolvers: option>, - typeDefs: option>, - fragmentMatcher: option, - name: option, - version: option, + ssrForceFetchDelay?: int, + ssrMode?: bool, + connectToDevTools?: bool, + queryDeduplication?: bool, + defaultOptions?: DefaultOptions.t, + assumeImmutableResults?: bool, + resolvers?: array, + typeDefs?: array, + fragmentMatcher?: FragmentMatcher.t, + name?: string, + version?: string, } let toJs: t => Js_.t = t => { - uri: t.uri, - credentials: t.credentials, - headers: t.headers, - link: t.link, + uri: ?t.uri, + credentials: ?t.credentials, + headers: ?t.headers, + link: ?t.link, cache: t.cache, - ssrForceFetchDelay: t.ssrForceFetchDelay, - ssrMode: t.ssrMode, - connectToDevTools: t.connectToDevTools, - queryDeduplication: t.queryDeduplication, - defaultOptions: t.defaultOptions->Belt.Option.map(DefaultOptions.toJs), - assumeImmutableResults: t.assumeImmutableResults, - resolvers: t.resolvers, - typeDefs: t.typeDefs, - fragmentMatcher: t.fragmentMatcher, - name: t.name, - version: t.version, + ssrForceFetchDelay: ?t.ssrForceFetchDelay, + ssrMode: ?t.ssrMode, + connectToDevTools: ?t.connectToDevTools, + queryDeduplication: ?t.queryDeduplication, + defaultOptions: ?t.defaultOptions->Belt.Option.map(DefaultOptions.toJs), + assumeImmutableResults: ?t.assumeImmutableResults, + resolvers: ?t.resolvers, + typeDefs: ?t.typeDefs, + fragmentMatcher: ?t.fragmentMatcher, + name: ?t.name, + version: ?t.version, } } @@ -610,22 +612,22 @@ let make: ( ) => { let jsClient = Js_.make( ApolloClientOptions.toJs({ - uri: uri, - credentials: credentials, - headers: headers, - link: link, - cache: cache, - ssrForceFetchDelay: ssrForceFetchDelay, - ssrMode: ssrMode, - connectToDevTools: connectToDevTools, - queryDeduplication: queryDeduplication, - defaultOptions: defaultOptions, - assumeImmutableResults: assumeImmutableResults, - resolvers: resolvers, - typeDefs: typeDefs, - fragmentMatcher: fragmentMatcher, - name: name, - version: version, + ?uri, + ?credentials, + ?headers, + ?link, + cache, + ?ssrForceFetchDelay, + ?ssrMode, + ?connectToDevTools, + ?queryDeduplication, + ?defaultOptions, + ?assumeImmutableResults, + ?resolvers, + ?typeDefs, + ?fragmentMatcher, + ?name, + ?version, }), ) @@ -661,16 +663,16 @@ let make: ( jsClient, ~options=MutationOptions.toJs( { - awaitRefetchQueries: awaitRefetchQueries, - context: context, - errorPolicy: errorPolicy, - fetchPolicy: fetchPolicy, + awaitRefetchQueries, + context, + errorPolicy, + fetchPolicy, mutation: Operation.query, - optimisticResponse: optimisticResponse, - updateQueries: updateQueries, - refetchQueries: refetchQueries, - update: update, - variables: variables, + optimisticResponse, + updateQueries, + refetchQueries, + update, + variables, }, ~mapJsVariables, ~safeParse, @@ -721,11 +723,11 @@ let make: ( jsClient, ~options=QueryOptions.toJs( { - fetchPolicy: fetchPolicy, + fetchPolicy, query: Operation.query, - variables: variables, - errorPolicy: errorPolicy, - context: context, + variables, + errorPolicy, + context, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, @@ -767,11 +769,11 @@ let make: ( jsClient ->Js_.readFragment( ~options={ - id: id, + id, fragment: Fragment.query, - fragmentName: fragmentName, - optimistic: optimistic, - canonizeResults: canonizeResults, + fragmentName, + optimistic, + canonizeResults, }, ~optimistic?, (), @@ -799,11 +801,11 @@ let make: ( jsClient, ~options=DataProxy.ReadQueryOptions.toJs( { - id: id, + id, query: Operation.query, - variables: variables, - optimistic: optimistic, - canonizeResults: canonizeResults, + variables, + optimistic, + canonizeResults, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, @@ -848,11 +850,11 @@ let make: ( jsClient, ~options=SubscriptionOptions.toJs( { - fetchPolicy: fetchPolicy, + fetchPolicy, query: Operation.query, - variables: variables, - errorPolicy: errorPolicy, - context: context, + variables, + errorPolicy, + context, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, @@ -904,13 +906,13 @@ let make: ( ->Js_.watchQuery( ~options=WatchQueryOptions.toJs( { - fetchPolicy: fetchPolicy, - nextFetchPolicy: nextFetchPolicy, + fetchPolicy, + nextFetchPolicy, query: Operation.query, - variables: variables, - errorPolicy: errorPolicy, - context: context, - pollInterval: pollInterval, + variables, + errorPolicy, + context, + pollInterval, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, @@ -932,12 +934,12 @@ let make: ( jsClient->Js_.writeFragment( ~options=DataProxy.WriteFragmentOptions.toJs( { - broadcast: broadcast, - data: data, - id: id, + broadcast, + data, + id, fragment: Fragment.query, - fragmentName: fragmentName, - overwrite: overwrite, + fragmentName, + overwrite, }, ~serialize=Fragment.serialize, ), @@ -960,12 +962,12 @@ let make: ( jsClient->Js_.writeQuery( ~options=DataProxy.WriteQueryOptions.toJs( { - broadcast: broadcast, - data: data, - id: id, + broadcast, + data, + id, query: Operation.query, - variables: variables, - overwrite: overwrite, + variables, + overwrite, }, ~mapJsVariables, ~serialize=Operation.serialize, @@ -992,25 +994,27 @@ let make: ( let safeParse = Utils.safeParse(Operation.parse) jsClient - ->Js_.updateQuery(~options=DataProxy.UpdateQueryOptions.toJs( - { - optimistic: optimistic, - canonizeResults: canonizeResults, - broadcast: broadcast, - id: id, - query: Operation.query, - variables: variables, - overwrite: overwrite, - }, - ~mapJsVariables, - ~serializeVariables=Operation.serializeVariables, - ), ~update=jsData => - jsData - ->Js.nullToOption - ->Belt.Option.map(Operation.parse) - ->update - ->Belt.Option.map(Operation.serialize) - ->Js.Nullable.fromOption + ->Js_.updateQuery( + ~options=DataProxy.UpdateQueryOptions.toJs( + { + optimistic, + canonizeResults, + broadcast, + id, + query: Operation.query, + variables, + overwrite, + }, + ~mapJsVariables, + ~serializeVariables=Operation.serializeVariables, + ), + ~update=jsData => + jsData + ->Js.nullToOption + ->Belt.Option.map(Operation.parse) + ->update + ->Belt.Option.map(Operation.serialize) + ->Js.Nullable.fromOption, ) ->Js.toOption ->Belt.Option.map(safeParse) @@ -1031,21 +1035,23 @@ let make: ( let safeParse = Utils.safeParse(Fragment.parse) jsClient - ->Js_.updateFragment(~options=DataProxy.UpdateFragmentOptions.toJs({ - optimistic: optimistic, - canonizeResults: canonizeResults, - broadcast: broadcast, - id: id, - fragment: Fragment.query, - fragmentName: fragmentName, - overwrite: overwrite, - }), ~update=jsData => - jsData - ->Js.nullToOption - ->Belt.Option.map(Fragment.parse) - ->update - ->Belt.Option.map(Fragment.serialize) - ->Js.Nullable.fromOption + ->Js_.updateFragment( + ~options=DataProxy.UpdateFragmentOptions.toJs({ + optimistic, + canonizeResults, + broadcast, + id, + fragment: Fragment.query, + fragmentName, + overwrite, + }), + ~update=jsData => + jsData + ->Js.nullToOption + ->Belt.Option.map(Fragment.parse) + ->update + ->Belt.Option.map(Fragment.serialize) + ->Js.Nullable.fromOption, ) ->Js.toOption ->Belt.Option.map(safeParse) @@ -1054,24 +1060,24 @@ let make: ( preserveJsPropsAndContext( jsClient, { - clearStore: clearStore, - extract: extract, - mutate: mutate, - onClearStore: onClearStore, - onResetStore: onResetStore, - query: query, - readFragment: readFragment, - readQuery: readQuery, - resetStore: resetStore, - restore: restore, - setLink: setLink, - stop: stop, - subscribe: subscribe, - watchQuery: watchQuery, - writeFragment: writeFragment, - writeQuery: writeQuery, - updateQuery: updateQuery, - updateFragment: updateFragment, + clearStore, + extract, + mutate, + onClearStore, + onResetStore, + query, + readFragment, + readQuery, + resetStore, + restore, + setLink, + stop, + subscribe, + watchQuery, + writeFragment, + writeQuery, + updateQuery, + updateFragment, }, ) } From 358dc446c026bf1c78f296c83f2615896ce4fab5 Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 25 Mar 2024 00:10:09 -0400 Subject: [PATCH 03/16] refactor: QueryHookOptions --- .../ApolloClient__React_Hooks_UseQuery.res | 27 +++++++++--------- .../react/types/ApolloClient__React_Types.res | 28 +++++++++---------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res index 0519f8c..a0e44ef 100644 --- a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res +++ b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res @@ -69,20 +69,19 @@ let useQuery: Operation.query, QueryHookOptions.toJs( { - client: client, - context: context, - displayName: displayName, - errorPolicy: errorPolicy, - fetchPolicy: fetchPolicy, - nextFetchPolicy: nextFetchPolicy, - onCompleted: onCompleted, - onError: onError, - notifyOnNetworkStatusChange: notifyOnNetworkStatusChange, - partialRefetch: partialRefetch, - pollInterval: pollInterval, - query: None, - skip: skip, - ssr: ssr, + client: ?client, + context: ?context, + displayName: ?displayName, + errorPolicy: ?errorPolicy, + fetchPolicy: ?fetchPolicy, + nextFetchPolicy: ?nextFetchPolicy, + onCompleted: ?onCompleted, + onError: ?onError, + notifyOnNetworkStatusChange: ?notifyOnNetworkStatusChange, + partialRefetch: ?partialRefetch, + pollInterval: ?pollInterval, + skip: ?skip, + ssr: ?ssr, variables: variables, }, ~mapJsVariables, diff --git a/src/@apollo/client/react/types/ApolloClient__React_Types.res b/src/@apollo/client/react/types/ApolloClient__React_Types.res index 6db080b..2f93ab2 100644 --- a/src/@apollo/client/react/types/ApolloClient__React_Types.res +++ b/src/@apollo/client/react/types/ApolloClient__React_Types.res @@ -47,24 +47,24 @@ module QueryHookOptions = { } type t<'data, 'variables> = { - query: option, + query?: Graphql.documentNode, // ...extends QueryFunctionOptions - displayName: option, - skip: option, - onCompleted: option => unit>, - onError: option unit>, + displayName?: string, + skip?: bool, + onCompleted?: Types.parseResult<'data> => unit, + onError?: ApolloError.t => unit, // ...extends BaseQueryOptions - client: option, - context: option, - errorPolicy: option, - fetchPolicy: option, - nextFetchPolicy: option, - notifyOnNetworkStatusChange: option, - partialRefetch: option, - pollInterval: option, + client?: ApolloClient.t, + context?: Js.Json.t, + errorPolicy?: ErrorPolicy.t, + fetchPolicy?: WatchQueryFetchPolicy.t, + nextFetchPolicy?: WatchQueryFetchPolicy.t, + notifyOnNetworkStatusChange?: bool, + partialRefetch?: bool, + pollInterval?: int, // INTENTIONALLY IGNORED (but now with safeParse and result unwrapping, maybe it shouldn't be?) // returnPartialData: option(bool), - ssr: option, + ssr?: bool, variables: 'variables, } From d32e6ff4546050b0f50b3fedaf220ac55be3c1db Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 25 Mar 2024 00:28:34 -0400 Subject: [PATCH 04/16] refactor: LazyQueryHookOptions --- ...ApolloClient__React_Hooks_UseLazyQuery.res | 53 +++++++++---------- .../react/types/ApolloClient__React_Types.res | 35 ++++++------ 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseLazyQuery.res b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseLazyQuery.res index b0aa2c8..0515b03 100644 --- a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseLazyQuery.res +++ b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseLazyQuery.res @@ -64,20 +64,18 @@ let useLazyQuery: Operation.query, LazyQueryHookOptions.toJs( { - client: client, - context: context, - displayName: displayName, - errorPolicy: errorPolicy, - fetchPolicy: fetchPolicy, - nextFetchPolicy: nextFetchPolicy, - onCompleted: onCompleted, - onError: onError, - notifyOnNetworkStatusChange: notifyOnNetworkStatusChange, - partialRefetch: partialRefetch, - pollInterval: pollInterval, - query: None, - ssr: ssr, - variables: None, + client: ?client, + context: ?context, + displayName: ?displayName, + errorPolicy: ?errorPolicy, + fetchPolicy: ?fetchPolicy, + nextFetchPolicy: ?nextFetchPolicy, + onCompleted: ?onCompleted, + onError: ?onError, + notifyOnNetworkStatusChange: ?notifyOnNetworkStatusChange, + partialRefetch: ?partialRefetch, + pollInterval: ?pollInterval, + ssr: ?ssr, }, ~safeParse, ~serializeVariables=Operation.serializeVariables, @@ -141,20 +139,19 @@ let useLazyQueryWithVariables: Operation.query, LazyQueryHookOptions.toJs( { - client: client, - context: context, - displayName: displayName, - errorPolicy: errorPolicy, - fetchPolicy: fetchPolicy, - nextFetchPolicy: nextFetchPolicy, - onCompleted: onCompleted, - onError: onError, - notifyOnNetworkStatusChange: notifyOnNetworkStatusChange, - partialRefetch: partialRefetch, - pollInterval: pollInterval, - query: None, - ssr: ssr, - variables: Some(variables), + client: ?client, + context: ?context, + displayName: ?displayName, + errorPolicy: ?errorPolicy, + fetchPolicy: ?fetchPolicy, + nextFetchPolicy: ?nextFetchPolicy, + onCompleted: ?onCompleted, + onError: ?onError, + notifyOnNetworkStatusChange: ?notifyOnNetworkStatusChange, + partialRefetch: ?partialRefetch, + pollInterval: ?pollInterval, + ssr: ?ssr, + variables: variables, }, ~safeParse, ~serializeVariables=Operation.serializeVariables, diff --git a/src/@apollo/client/react/types/ApolloClient__React_Types.res b/src/@apollo/client/react/types/ApolloClient__React_Types.res index 2f93ab2..f9982f2 100644 --- a/src/@apollo/client/react/types/ApolloClient__React_Types.res +++ b/src/@apollo/client/react/types/ApolloClient__React_Types.res @@ -125,24 +125,24 @@ module LazyQueryHookOptions = { } type t<'data, 'variables> = { - query: option, + query?: Graphql.documentNode, // ...extends QueryFunctionOptions - displayName: option, - onCompleted: option => unit>, - onError: option unit>, + displayName?: string, + onCompleted?: Types.parseResult<'data> => unit, + onError?: ApolloError.t => unit, // ...extends BaseQueryOptions - client: option, - context: option, - errorPolicy: option, - fetchPolicy: option, - nextFetchPolicy: option, - notifyOnNetworkStatusChange: option, - partialRefetch: option, - pollInterval: option, + client?: ApolloClient.t, + context?: Js.Json.t, + errorPolicy?: ErrorPolicy.t, + fetchPolicy?: WatchQueryFetchPolicy.t, + nextFetchPolicy?: WatchQueryFetchPolicy.t, + notifyOnNetworkStatusChange?: bool, + partialRefetch?: bool, + pollInterval?: int, // INTENTIONALLY IGNORED (but now with safeParse and result unwrapping, maybe it shouldn't be?) - // returnPartialData: option(bool), - ssr: option, - variables: option<'variables>, + // returnPartialData?: bool, + ssr?: bool, + variables?: 'variables, } let toJs = ( @@ -166,7 +166,10 @@ module LazyQueryHookOptions = { pollInterval: ?t.pollInterval, partialRefetch: ?t.partialRefetch, ssr: ?t.ssr, - variables: ?t.variables->Belt.Option.map(serializeVariables), + variables: ?switch t.variables { + | Some(variables) => serializeVariables(variables)->Some + | None => None + } } } From c7b953683888dedf745c6a8003eb516c21e8e525 Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 25 Mar 2024 00:29:01 -0400 Subject: [PATCH 05/16] refactor: QueryLazyOptions --- .../client/react/types/ApolloClient__React_Types.res | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/@apollo/client/react/types/ApolloClient__React_Types.res b/src/@apollo/client/react/types/ApolloClient__React_Types.res index f9982f2..def1abb 100644 --- a/src/@apollo/client/react/types/ApolloClient__React_Types.res +++ b/src/@apollo/client/react/types/ApolloClient__React_Types.res @@ -63,7 +63,7 @@ module QueryHookOptions = { partialRefetch?: bool, pollInterval?: int, // INTENTIONALLY IGNORED (but now with safeParse and result unwrapping, maybe it shouldn't be?) - // returnPartialData: option(bool), + // returnPartialData?: bool, ssr?: bool, variables: 'variables, } @@ -181,7 +181,7 @@ module QueryLazyOptions = { // } type t<'jsVariables> = { variables: 'jsVariables, - context: option, + context?: Js.Json.t, } } @@ -617,7 +617,7 @@ module QueryTuple = { ) => ( (~context=?, ~mapJsVariables=ApolloClient__Utils.identity, variables) => jsExecuteQuery({ - context, + ?context, variables: variables->serializeVariables->mapJsVariables, }) |> Js.Promise.then_(jsResult => QueryResult.fromJs( @@ -661,7 +661,7 @@ module QueryTuple__noVariables = { ) => ( (~context=?, ()) => jsExecuteQuery({ - context, + ?context, variables: variables->serializeVariables->mapJsVariables, }) |> Js.Promise.then_(jsResult => QueryResult.fromJs( From 101cecd8ba14b75d412bdb5eea09e08900ef21c0 Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 25 Mar 2024 00:41:45 -0400 Subject: [PATCH 06/16] missed deprecation notices --- src/@apollo/client/core/ApolloClient__Core_ApolloClient.res | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res index c544392..56c13b9 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res +++ b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res @@ -53,6 +53,7 @@ module DefaultWatchQueryOptions = { context: ?t.context, } + @deprecated("Just construct t instead") let make = (~fetchPolicy=?, ~errorPolicy=?, ~context=?, ()) => { ?fetchPolicy, ?errorPolicy, @@ -84,6 +85,7 @@ module DefaultQueryOptions = { context: ?t.context, } + @deprecated("Just construct t instead") let make = (~fetchPolicy=?, ~errorPolicy=?, ~context=?, ()) => { ?fetchPolicy, ?errorPolicy, From ce946438e331171ba0aab35e60d2aa9bd270782d Mon Sep 17 00:00:00 2001 From: Rob Date: Sun, 7 Apr 2024 21:19:36 -0400 Subject: [PATCH 07/16] more stuff --- .gitattributes | 2 + .../core/ApolloClient__Core_ApolloClient.res | 16 +++---- .../client/core/ApolloClient__Core_Types.res | 6 +-- .../ApolloClient__Core_WatchQueryOptions.res | 48 +++++++++---------- .../ApolloClient__React_Hooks_UseQuery.res | 2 +- .../react/types/ApolloClient__React_Types.res | 4 +- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/.gitattributes b/.gitattributes index 7e80300..754702d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,4 @@ *.re linguist-language=Reason *.rei linguist-language=Reason +*.res linguist-language=ReScript +*.resi linguist-language=ReScript diff --git a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res index 56c13b9..b5cf471 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res +++ b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res @@ -725,11 +725,11 @@ let make: ( jsClient, ~options=QueryOptions.toJs( { - fetchPolicy, + ?fetchPolicy, query: Operation.query, variables, - errorPolicy, - context, + ?errorPolicy, + ?context, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, @@ -908,13 +908,13 @@ let make: ( ->Js_.watchQuery( ~options=WatchQueryOptions.toJs( { - fetchPolicy, - nextFetchPolicy, + ?fetchPolicy, + ?nextFetchPolicy, query: Operation.query, variables, - errorPolicy, - context, - pollInterval, + ?errorPolicy, + ?context, + ?pollInterval, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, diff --git a/src/@apollo/client/core/ApolloClient__Core_Types.res b/src/@apollo/client/core/ApolloClient__Core_Types.res index b3152a8..dffa03e 100644 --- a/src/@apollo/client/core/ApolloClient__Core_Types.res +++ b/src/@apollo/client/core/ApolloClient__Core_Types.res @@ -27,20 +27,20 @@ module PureQueryOptions = { query: Graphql.documentNode, // We don't allow optional variables because it's not typesafe variables: 'jsVariables, - context: option, + context?: Js.Json.t, } } type t<'jsVariables> = { query: Graphql.documentNode, variables: 'jsVariables, - context: option, + context?: Js.Json.t, } let toJs: t<'jsVariables> => Js_.t<'jsVariables> = t => { query: t.query, variables: t.variables, - context: t.context, + context: ?t.context, } } diff --git a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res index 0ed6ecf..cf54df3 100644 --- a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res +++ b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res @@ -88,22 +88,22 @@ module WatchQueryFetchPolicy = { module QueryOptions = { module Js_ = { type t<'jsVariables> = { - fetchPolicy: option, + fetchPolicy?: FetchPolicy.Js_.t, // ...extends QueryBaseOptions query: Graphql.documentNode, // We don't allow optional variables because it's not typesafe variables: 'jsVariables, - errorPolicy: option, - context: option, + errorPolicy?: ErrorPolicy.Js_.t, + context?: Js.Json.t, } } type t<'jsVariables> = { - fetchPolicy: option, + fetchPolicy?: FetchPolicy.t, query: Graphql.documentNode, variables: 'jsVariables, - errorPolicy: option, - context: option, + errorPolicy?: ErrorPolicy.t, + context?: Js.Json.t, } let toJs: ( @@ -111,37 +111,37 @@ module QueryOptions = { ~mapJsVariables: 'jsVariables => 'jsVariables, ~serializeVariables: 'variables => 'jsVariables, ) => Js_.t<'jsVariables> = (t, ~mapJsVariables, ~serializeVariables) => { - fetchPolicy: t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), query: t.query, variables: t.variables->serializeVariables->mapJsVariables, - errorPolicy: t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - context: t.context, + errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + context: ?t.context, } } module WatchQueryOptions = { module Js_ = { type t<'jsVariables> = { - fetchPolicy: option, - nextFetchPolicy: option, + fetchPolicy?: WatchQueryFetchPolicy.Js_.t, + nextFetchPolicy?: WatchQueryFetchPolicy.Js_.t, // ...extends QueryBaseOptions query: Graphql.documentNode, // We don't allow optional variables because it's not typesafe variables: 'jsVariables, - errorPolicy: option, - context: option, - pollInterval: option, + errorPolicy?: ErrorPolicy.Js_.t, + context?: Js.Json.t, + pollInterval?: int, } } type t<'jsVariables> = { - fetchPolicy: option, - nextFetchPolicy: option, + fetchPolicy?: WatchQueryFetchPolicy.t, + nextFetchPolicy?: WatchQueryFetchPolicy.t, query: Graphql.documentNode, variables: 'jsVariables, - errorPolicy: option, - context: option, - pollInterval: option, + errorPolicy?: ErrorPolicy.t, + context?: Js.Json.t, + pollInterval?: int, } let toJs: ( @@ -149,13 +149,13 @@ module WatchQueryOptions = { ~mapJsVariables: 'jsVariables => 'jsVariables, ~serializeVariables: 'variables => 'jsVariables, ) => Js_.t<'jsVariables> = (t, ~mapJsVariables, ~serializeVariables) => { - fetchPolicy: t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), - nextFetchPolicy: t.nextFetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), + nextFetchPolicy: ?t.nextFetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), query: t.query, variables: t.variables->serializeVariables->mapJsVariables, - errorPolicy: t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - context: t.context, - pollInterval: t.pollInterval, + errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + context: ?t.context, + pollInterval: ?t.pollInterval, } } diff --git a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res index a0e44ef..e6d3f79 100644 --- a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res +++ b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res @@ -116,7 +116,7 @@ module Extend = (M: Operation) => { RefetchQueryDescription.PureQueryOptions({ query: M.query, variables: jsVariables, - context: context, + context: ?context, }) } diff --git a/src/@apollo/client/react/types/ApolloClient__React_Types.res b/src/@apollo/client/react/types/ApolloClient__React_Types.res index def1abb..4c92dc4 100644 --- a/src/@apollo/client/react/types/ApolloClient__React_Types.res +++ b/src/@apollo/client/react/types/ApolloClient__React_Types.res @@ -194,8 +194,8 @@ module QueryResult = { module Js_ = { type t_fetchMoreOptions_updateQueryOptions<'jsData, 'jsVariables> = { - fetchMoreResult: option<'jsData>, - variables: option<'jsVariables>, + fetchMoreResult?: 'jsData, + variables?: 'jsVariables, } type t_fetchMoreOptions<'jsData, 'jsVariables> = { From e324833cc3967baca128d7e855a50c0c0f684e11 Mon Sep 17 00:00:00 2001 From: Rob Date: Sun, 7 Apr 2024 21:20:46 -0400 Subject: [PATCH 08/16] drop bs-platform support bs-platform 9 -> rescript 9 has been around for quite some time now --- EXAMPLES/bsconfig.json | 4 ---- EXAMPLES/package.json | 2 +- bsconfig.json | 4 ---- package.json | 11 ++++------- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/EXAMPLES/bsconfig.json b/EXAMPLES/bsconfig.json index 4518b65..f00081a 100644 --- a/EXAMPLES/bsconfig.json +++ b/EXAMPLES/bsconfig.json @@ -20,10 +20,6 @@ "version": 4, "mode": "automatic" }, - "reason": { - "react-jsx": 3 - }, - "refmt": 3, "sources": [ { "dir": "src", diff --git a/EXAMPLES/package.json b/EXAMPLES/package.json index d3a5048..cd01690 100644 --- a/EXAMPLES/package.json +++ b/EXAMPLES/package.json @@ -10,7 +10,7 @@ "start": "rescript build -with-deps -w" }, "devDependencies": { - "@reasonml-community/graphql-ppx": "1.2.3", + "@reasonml-community/graphql-ppx": "1.2.4-1345e061.0", "graphql-client-example-server": "1.5.2", "html-webpack-plugin": "5.5.0", "rescript": "10.1.2", diff --git a/bsconfig.json b/bsconfig.json index 68edf65..e21f186 100644 --- a/bsconfig.json +++ b/bsconfig.json @@ -6,10 +6,6 @@ "in-source": true } ], - "reason": { - "react-jsx": 3 - }, - "refmt": 3, "jsx": { "version": 4, "mode": "automatic" diff --git a/package.json b/package.json index 9dcaf73..25c879f 100644 --- a/package.json +++ b/package.json @@ -16,15 +16,16 @@ "scripts": { "build": "rescript build -with-deps", "clean": "rescript clean", + "format:ci": "rescript format -check -all", "start": "rescript build -with-deps -w", "test": "jest" }, "devDependencies": { "@apollo/client": "^3.5.0", - "@reasonml-community/graphql-ppx": "^1.0.0", + "@reasonml-community/graphql-ppx": "1.2.4-1345e061.0", "@rescript/react": "~0.11.0", "rescript": "~10.1.2", - "graphql": "^14.0.0", + "graphql": "^15.0.0", "jest": "26.5.3", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -34,15 +35,11 @@ "@apollo/client": "^3.5.0", "@reasonml-community/graphql-ppx": "^1.0.0", "@rescript/react": "~0.10. || ~0.11.0", - "bs-platform": "^8.2.0 || ^9.0.0", - "rescript": "^9.0.0 || ^10.0.0" + "rescript": "^10.0.0" }, "peerDependenciesMeta": { "rescript": { "optional": true - }, - "bs-platform": { - "optional": true } } } From 21b820f09f8255d5cd690c0cc40b168a6a864fc9 Mon Sep 17 00:00:00 2001 From: Rob Date: Fri, 13 Sep 2024 21:59:21 -0400 Subject: [PATCH 09/16] more changes --- .../core/ApolloClient__Core_ApolloClient.res | 10 ++++++++-- .../core/ApolloClient__Core_ObservableQuery.res | 13 +++++++------ .../link/core/ApolloClient__Link_Core_Types.res | 14 +++++++------- .../link/http/ApolloClient__Link_Http_HttpLink.res | 14 +++++++------- ...oClient__Link_Http_SelectHttpOptionsAndBody.res | 14 +++++++------- .../ApolloClient__Link_Retry_DelayFunction.res | 6 +++--- .../ApolloClient__Link_Retry_RetryFunction.res | 6 +++--- 7 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res index b5cf471..d1f2033 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res +++ b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res @@ -80,8 +80,14 @@ module DefaultQueryOptions = { } let toJs: t => Js_.t = t => { - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), - errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + fetchPolicy: ?switch t.fetchPolicy { + | Some(fetchPolicy) => FetchPolicy.toJs(fetchPolicy)->Some + | None => None + }, + errorPolicy: ?switch t.errorPolicy { + | Some(errorPolicy) => ErrorPolicy.toJs(errorPolicy)->Some + | None => None + }, context: ?t.context, } diff --git a/src/@apollo/client/core/ApolloClient__Core_ObservableQuery.res b/src/@apollo/client/core/ApolloClient__Core_ObservableQuery.res index 68accfc..5fd0041 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ObservableQuery.res +++ b/src/@apollo/client/core/ApolloClient__Core_ObservableQuery.res @@ -52,13 +52,14 @@ module ObservableQuery = { // ...extends Observable> // (callback: (value: T) => R): Observable; @send external map: (t<'t>, 't => 'r) => t<'r> = "map" + + /** + We should be able to just map, but it's broken: + https://github.com/apollographql/apollo-client/issues/6144 + This is not any sort of real map, of course. It just returns an observable + with a subcribe method that builds the transformation into onNext :( + */ let fakeMap: (t<'t>, ('t, Js.Exn.t => unit) => option<'r>) => t<'r> = (js, fn) => - @ocaml.doc(" - * We should be able to just map, but it's broken: - * https://github.com/apollographql/apollo-client/issues/6144 - * This is not any sort of real map, of course. It just returns an observable - * with a subcribe method that builds the transformation into onNext :( - ") %raw(` function (js, fn) { var originalSubscribe = js.subscribe.bind(js); 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..ffa890a 100644 --- a/src/@apollo/client/link/core/ApolloClient__Link_Core_Types.res +++ b/src/@apollo/client/link/core/ApolloClient__Link_Core_Types.res @@ -16,10 +16,10 @@ module GraphQLRequest = { // } type t = { query: Graphql.documentNode, - variables: option, - operationName: option, - context: option, - extensions: option, + variables?: Js.Json.t, + operationName?: string, + context?: Js.Json.t, + extensions?: Js.Json.t, } } @@ -118,7 +118,7 @@ module FetchResult = { ~graphQLErrors=?js.errors, safeParse, ) - {data: data, error: error, extensions: js.extensions, context: js.context} + {data, error, extensions: js.extensions, context: js.context} } let fromError: ApolloError.t => t<'data> = error => { @@ -139,7 +139,7 @@ module FetchResult = { switch fetchResult { | {data: Some(data)} => Ok({ - data: data, + data, error: fetchResult.error, extensions: fetchResult.extensions, context: fetchResult.context, @@ -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/http/ApolloClient__Link_Http_HttpLink.res b/src/@apollo/client/link/http/ApolloClient__Link_Http_HttpLink.res index 6d1f0c5..6f8f82c 100644 --- a/src/@apollo/client/link/http/ApolloClient__Link_Http_HttpLink.res +++ b/src/@apollo/client/link/http/ApolloClient__Link_Http_HttpLink.res @@ -32,11 +32,11 @@ let make: ( (), ) => Js_.make({ - uri: uri, - includeExtensions: includeExtensions, - fetch: fetch, - headers: headers, - credentials: credentials, - fetchOptions: fetchOptions, - useGETForQueries: useGETForQueries, + ?uri, + ?includeExtensions, + ?fetch, + ?headers, + ?credentials, + ?fetchOptions, + ?useGETForQueries, }) diff --git a/src/@apollo/client/link/http/ApolloClient__Link_Http_SelectHttpOptionsAndBody.res b/src/@apollo/client/link/http/ApolloClient__Link_Http_SelectHttpOptionsAndBody.res index 73a25b6..c5ab8d9 100644 --- a/src/@apollo/client/link/http/ApolloClient__Link_Http_SelectHttpOptionsAndBody.res +++ b/src/@apollo/client/link/http/ApolloClient__Link_Http_SelectHttpOptionsAndBody.res @@ -30,13 +30,13 @@ module HttpOptions = { type t_fetch type t = { - uri: option, - includeExtensions: option, - fetch: option, - headers: option, - credentials: option, - fetchOptions: option, - useGETForQueries: option, + uri?: UriFunction.Js_.t, + includeExtensions?: bool, + fetch?: t_fetch, + headers?: Js.Json.t, + credentials?: string, + fetchOptions?: Js.Json.t, + useGETForQueries?: bool, } } 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..bcaf0bd 100644 --- a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_DelayFunction.res +++ b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_DelayFunction.res @@ -21,9 +21,9 @@ module DelayFunctionOptions = { // jitter?: boolean; // } type t = { - initial: option, - max: option, - jitter: option, + initial?: int, + max?: int, + jitter?: int, } module Js_ = { 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..e68df29 100644 --- a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryFunction.res +++ b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryFunction.res @@ -21,18 +21,18 @@ module RetryFunctionOptions = { // retryIf?: (error: any, operation: Operation) => boolean | Promise; // } type t = { - max: option, + max?: int, retryIf: (option, Operation.Js_.t) => Js.Promise.t, } } type t = { - max: option, + max?: int, retryIf: (~error: option, ~operation: Operation.t) => Js.Promise.t, } let toJs: t => Js_.t = t => { - max: t.max, + max: ?t.max, retryIf: (error, operation) => t.retryIf(~error, ~operation=operation->Operation.fromJs), } } From cfbfb129973ec3e8ac93bb589c81ff4fabce10a6 Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 7 Oct 2024 18:09:56 -0400 Subject: [PATCH 10/16] DataProxy --- .../core/ApolloClient__Cache_Core_Cache.res | 44 +++--- ...olloClient__Cache_Core_Types_DataProxy.res | 138 +++++++++--------- .../core/ApolloClient__Core_ApolloClient.res | 44 +++--- 3 files changed, 113 insertions(+), 113 deletions(-) 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..1a6e86e 100644 --- a/src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res +++ b/src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res @@ -188,9 +188,9 @@ module ApolloCache = { ~options={ id: id, fragment: Fragment.query, - fragmentName: fragmentName, - optimistic: optimistic, - canonizeResults: canonizeResults, + fragmentName: ?fragmentName, + optimistic: ?optimistic, + canonizeResults: ?canonizeResults, }, ~optimistic?, (), @@ -218,11 +218,11 @@ module ApolloCache = { ->Js_.readQuery( ~options=DataProxy.ReadQueryOptions.toJs( { - id: id, + id: ?id, query: Operation.query, variables: variables, - optimistic: optimistic, - canonizeResults: canonizeResults, + optimistic: ?optimistic, + canonizeResults: ?canonizeResults, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, @@ -247,12 +247,12 @@ module ApolloCache = { js->Js_.writeFragment( ~options=DataProxy.WriteFragmentOptions.toJs( { - broadcast: broadcast, + broadcast: ?broadcast, data: data, id: id, fragment: Fragment.query, - fragmentName: fragmentName, - overwrite: overwrite, + fragmentName: ?fragmentName, + overwrite: ?overwrite, }, ~serialize=Fragment.serialize, ), @@ -275,12 +275,12 @@ module ApolloCache = { js->Js_.writeQuery( ~options=DataProxy.WriteQueryOptions.toJs( { - broadcast: broadcast, + broadcast: ?broadcast, data: data, - id: id, + id: ?id, query: Operation.query, variables: variables, - overwrite: overwrite, + overwrite: ?overwrite, }, ~mapJsVariables, ~serialize=Operation.serialize, @@ -309,13 +309,13 @@ module ApolloCache = { js ->Js_.updateQuery(~options=DataProxy.UpdateQueryOptions.toJs( { - optimistic: optimistic, - canonizeResults: canonizeResults, - broadcast: broadcast, - id: id, + optimistic: ?optimistic, + canonizeResults: ?canonizeResults, + broadcast: ?broadcast, + id: ?id, query: Operation.query, variables: variables, - overwrite: overwrite, + overwrite: ?overwrite, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, @@ -347,13 +347,13 @@ module ApolloCache = { js ->Js_.updateFragment(~options=DataProxy.UpdateFragmentOptions.toJs({ - optimistic: optimistic, - canonizeResults: canonizeResults, - broadcast: broadcast, + optimistic: ?optimistic, + canonizeResults: ?canonizeResults, + broadcast: ?broadcast, id: id, fragment: Fragment.query, - fragmentName: fragmentName, - overwrite: overwrite, + fragmentName: ?fragmentName, + overwrite: ?overwrite, }), ~update=jsData => jsData ->Js.nullToOption diff --git a/src/@apollo/client/cache/core/types/ApolloClient__Cache_Core_Types_DataProxy.res b/src/@apollo/client/cache/core/types/ApolloClient__Cache_Core_Types_DataProxy.res index d8d1e46..e57b0c5 100644 --- a/src/@apollo/client/cache/core/types/ApolloClient__Cache_Core_Types_DataProxy.res +++ b/src/@apollo/client/cache/core/types/ApolloClient__Cache_Core_Types_DataProxy.res @@ -17,10 +17,10 @@ module ReadQueryOptions = { query: Graphql.documentNode, // We don't allow optional variables because it's not typesafe variables: 'jsVariables, - id: option, - // returnPartialData: option, - optimistic: option, - canonizeResults: option, + id?: string, + // returnPartialData?: bool, + optimistic?: bool, + canonizeResults?: bool, } } @@ -33,10 +33,10 @@ module ReadQueryOptions = { ) => Js_.t<'jsVariables> = (t, ~mapJsVariables=Utils.identity, ~serializeVariables) => { query: t.query, variables: t.variables->serializeVariables->mapJsVariables, - id: t.id, - // returnPartialData: t.returnPartialData, - optimistic: t.optimistic, - canonizeResults: t.canonizeResults, + id: ?t.id, + // returnPartialData: ?t.returnPartialData, + optimistic: ?t.optimistic, + canonizeResults: ?t.canonizeResults, } } @@ -58,10 +58,10 @@ module ReadFragmentOptions = { fragment: Graphql.documentNode, // We don't allow optional variables because it's not typesafe // variables: 'jsVariables, - fragmentName: option, - // returnPartialData: option, - optimistic: option, - canonizeResults: option, + fragmentName?: string, + // returnPartialData?: bool, + optimistic?: bool, + canonizeResults?: bool, } } @@ -70,10 +70,10 @@ module ReadFragmentOptions = { fragment: Graphql.documentNode, // We don't allow optional variables because it's not typesafe // variables: 'jsVariables, - fragmentName: option, - // returnPartialData: option, - optimistic: option, - canonizeResults: option, + fragmentName?: string, + // returnPartialData?: bool, + optimistic?: bool, + canonizeResults?: bool, } } @@ -85,23 +85,23 @@ module WriteQueryOptions = { // } type t<'jsData, 'jsVariables> = { data: 'jsData, - broadcast: option, - overwrite: option, + broadcast?: bool, + overwrite?: bool, // ...extends Query query: Graphql.documentNode, // We don't allow optional variables because it's not typesafe variables: 'jsVariables, - id: option, + id?: string, } } type t<'data, 'variables> = { data: 'data, - broadcast: option, - overwrite: option, + broadcast?: bool, + overwrite?: bool, query: Graphql.documentNode, variables: 'variables, - id: option, + id?: string, } let toJs: ( @@ -116,11 +116,11 @@ module WriteQueryOptions = { ~serializeVariables, ) => { data: t.data->serialize, - broadcast: t.broadcast, - overwrite: t.overwrite, + broadcast: ?t.broadcast, + overwrite: ?t.overwrite, query: t.query, variables: t.variables->serializeVariables->mapJsVariables, - id: t.id, + id: ?t.id, } } @@ -132,12 +132,12 @@ module WriteFragmentOptions = { // } type t<'jsData, 'jsVariables> = { data: 'jsData, - broadcast: option, - overwrite: option, + broadcast?: bool, + overwrite?: bool, // ...extends Fragment id: string, fragment: Graphql.documentNode, - fragmentName: option, + fragmentName?: string, // I think fragment variables are still experimental? // // We don't allow optional variables because it's not typesafe // variables: 'jsVariables, @@ -146,11 +146,11 @@ module WriteFragmentOptions = { type t<'data, 'variables> = { data: 'data, - broadcast: option, - overwrite: option, + broadcast?: bool, + overwrite?: bool, id: string, fragment: Graphql.documentNode, - fragmentName: option, + fragmentName?: string, // variables: 'variables, } @@ -161,11 +161,11 @@ module WriteFragmentOptions = { ) => // ~serializeVariables: 'variables => 'jsVariables Js_.t<'jsData, 'jsVariables> = (t, ~serialize) => { data: t.data->serialize, - broadcast: t.broadcast, - overwrite: t.overwrite, + broadcast: ?t.broadcast, + overwrite: ?t.overwrite, id: t.id, fragment: t.fragment, - fragmentName: t.fragmentName, + fragmentName: ?t.fragmentName, // variables: t.variables->serializeVariables->mapJsVariables, } } @@ -179,29 +179,29 @@ module UpdateQueryOptions = { type t<'jsVariables> = { // ReadQueryOptions // ...extends Query - id: option, + id?: string, query: Graphql.documentNode, // We don't allow optional variables because it's not typesafe variables: 'jsVariables, // ...extends ReadQueryOptions - optimistic: option, - canonizeResults: option, + optimistic?: bool, + canonizeResults?: bool, // ...extends Omit - // returnPartialData: option, // Don't believe this is supported by graphql-ppx - broadcast: option, - overwrite: option, + // returnPartialData?: bool, // Don't believe this is supported by graphql-ppx + broadcast?: bool, + overwrite?: bool, } } type t<'variables> = { - id: option, + id?: string, query: Graphql.documentNode, variables: 'variables, - optimistic: option, - canonizeResults: option, - // returnPartialData: option, // Don't believe this is supported by graphql-ppx - broadcast: option, - overwrite: option, + optimistic?: bool, + canonizeResults?: bool, + // returnPartialData?: bool, // Don't believe this is supported by graphql-ppx + broadcast?: bool, + overwrite?: bool, } let toJs: ( @@ -209,14 +209,14 @@ module UpdateQueryOptions = { ~mapJsVariables: 'jsVariables => 'jsVariables=?, ~serializeVariables: 'variables => 'jsVariables, ) => Js_.t<'jsVariables> = (t, ~mapJsVariables=Utils.identity, ~serializeVariables) => { - id: t.id, + id: ?t.id, query: t.query, variables: t.variables->serializeVariables->mapJsVariables, - optimistic: t.optimistic, - canonizeResults: t.canonizeResults, - broadcast: t.broadcast, - overwrite: t.overwrite, - // returnPartialData: t.returnPartialData, // Don't believe this is supported by graphql-ppx + optimistic: ?t.optimistic, + canonizeResults: ?t.canonizeResults, + broadcast: ?t.broadcast, + overwrite: ?t.overwrite, + // returnPartialData: ?t.returnPartialData, // Don't believe this is supported by graphql-ppx } } @@ -231,40 +231,40 @@ module UpdateFragmentOptions = { // ...extends Fragment id: string, fragment: Graphql.documentNode, - fragmentName: option, + fragmentName?: string, // We don't allow optional variables because it's not typesafe // variables: 'jsVariables, // ...extends ReadFragmentOptions - optimistic: option, - canonizeResults: option, + optimistic?: bool, + canonizeResults?: bool, // ...extends Omit - // returnPartialData: option, // Don't believe this is supported by graphql-ppx - broadcast: option, - overwrite: option, + // returnPartialData?: bool, // Don't believe this is supported by graphql-ppx + broadcast?: bool, + overwrite?: bool, } } type t<'variables> = { id: string, fragment: Graphql.documentNode, - fragmentName: option, + fragmentName?: string, // variables: 'variables, - optimistic: option, - canonizeResults: option, - // returnPartialData: option, // Don't believe this is supported by graphql-ppx - broadcast: option, - overwrite: option, + optimistic?: bool, + canonizeResults?: bool, + // returnPartialData?: bool, // Don't believe this is supported by graphql-ppx + broadcast?: bool, + overwrite?: bool, } let toJs: t<'variables> => Js_.t<'jsVariables> = t => { id: t.id, fragment: t.fragment, - fragmentName: t.fragmentName, + fragmentName: ?t.fragmentName, // variables: t.variables, - optimistic: t.optimistic, - canonizeResults: t.canonizeResults, - broadcast: t.broadcast, - overwrite: t.overwrite, + optimistic: ?t.optimistic, + canonizeResults: ?t.canonizeResults, + broadcast: ?t.broadcast, + overwrite: ?t.overwrite, // returnPartialData: t.returnPartialData, // Don't believe this is supported by graphql-ppx } } diff --git a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res index d1f2033..6bb12ad 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res +++ b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res @@ -779,9 +779,9 @@ let make: ( ~options={ id, fragment: Fragment.query, - fragmentName, - optimistic, - canonizeResults, + ?fragmentName, + ?optimistic, + ?canonizeResults, }, ~optimistic?, (), @@ -809,11 +809,11 @@ let make: ( jsClient, ~options=DataProxy.ReadQueryOptions.toJs( { - id, + ?id, query: Operation.query, variables, - optimistic, - canonizeResults, + ?optimistic, + ?canonizeResults, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, @@ -942,12 +942,12 @@ let make: ( jsClient->Js_.writeFragment( ~options=DataProxy.WriteFragmentOptions.toJs( { - broadcast, + ?broadcast, data, id, fragment: Fragment.query, - fragmentName, - overwrite, + ?fragmentName, + ?overwrite, }, ~serialize=Fragment.serialize, ), @@ -970,12 +970,12 @@ let make: ( jsClient->Js_.writeQuery( ~options=DataProxy.WriteQueryOptions.toJs( { - broadcast, + ?broadcast, data, - id, + ?id, query: Operation.query, variables, - overwrite, + ?overwrite, }, ~mapJsVariables, ~serialize=Operation.serialize, @@ -1005,13 +1005,13 @@ let make: ( ->Js_.updateQuery( ~options=DataProxy.UpdateQueryOptions.toJs( { - optimistic, - canonizeResults, - broadcast, - id, + ?optimistic, + ?canonizeResults, + ?broadcast, + ?id, query: Operation.query, variables, - overwrite, + ?overwrite, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, @@ -1045,13 +1045,13 @@ let make: ( jsClient ->Js_.updateFragment( ~options=DataProxy.UpdateFragmentOptions.toJs({ - optimistic, - canonizeResults, - broadcast, + ?optimistic, + ?canonizeResults, + ?broadcast, id, fragment: Fragment.query, - fragmentName, - overwrite, + ?fragmentName, + ?overwrite, }), ~update=jsData => jsData From 3d0b221c14cdd098f1778e299b4c02238fe81c26 Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 7 Oct 2024 18:39:45 -0400 Subject: [PATCH 11/16] the rest? --- .gitignore | 1 + .../ApolloClient__Cache_InMemory_Policies.res | 41 +++--- ...t__Cache_InMemory_Policies_FieldPolicy.res | 18 +-- .../core/ApolloClient__Core_ApolloClient.res | 22 ++-- .../ApolloClient__Core_WatchQueryOptions.res | 85 ++++++------ .../ApolloClient__Link_Retry_RetryLink.res | 16 +-- ...lloClient__React_Hooks_UseSubscription.res | 13 +- .../react/types/ApolloClient__React_Types.res | 122 +++++++++--------- ...ApolloClient__SubscriptionsTransportWs.res | 57 ++++---- 9 files changed, 188 insertions(+), 187 deletions(-) diff --git a/.gitignore b/.gitignore index 2ba7c1f..cb55cfb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ yarn-error.log .vscode/ lib/ node_modules/ +.yarn/install-state.gz \ No newline at end of file diff --git a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res index 768d6fe..e93a2bf 100644 --- a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res +++ b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res @@ -51,11 +51,11 @@ module TypePolicy = { // }; // }; type t = { - keyFields: option, - queryType: option, - mutationType: option, - subscriptionType: option, - fields: option>, + keyFields?: KeyArgs.Js_.t, + queryType?: bool, + mutationType?: bool, + subscriptionType?: bool, + fields?: Js.Dict.t, } } @@ -71,19 +71,19 @@ module TypePolicy = { type t_fields = array<(fieldKey, t_field)> type t = { - keyFields: option, - queryType: option, - mutationType: option, - subscriptionType: option, - fields: option, + keyFields?: KeyArgs.t, + queryType?: bool, + mutationType?: bool, + subscriptionType?: bool, + fields?: t_fields, } let toJs: (. t) => Js_.t = (. t) => { - keyFields: t.keyFields->Belt.Option.map(KeyArgs.toJs), - queryType: t.queryType, - mutationType: t.mutationType, - subscriptionType: t.subscriptionType, - fields: t.fields->Belt.Option.map(fields => + keyFields: ?t.keyFields->Belt.Option.map(KeyArgs.toJs), + queryType: ?t.queryType, + mutationType: ?t.mutationType, + subscriptionType: ?t.subscriptionType, + fields: ?t.fields->Belt.Option.map(fields => fields ->Belt.Array.map(((fieldKey, t_field)) => ( fieldKey, @@ -104,6 +104,7 @@ module TypePolicy = { ), } + @deprecated("Construct the record directly instead") let make: ( ~fields: t_fields=?, ~keyFields: KeyArgs.t=?, @@ -112,11 +113,11 @@ module TypePolicy = { ~subscriptionType: bool=?, unit, ) => t = (~fields=?, ~keyFields=?, ~mutationType=?, ~queryType=?, ~subscriptionType=?, ()) => { - fields, - keyFields, - mutationType, - queryType, - subscriptionType, + ?fields, + ?keyFields, + ?mutationType, + ?queryType, + ?subscriptionType, } } 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..3668043 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 @@ -210,9 +210,9 @@ module FieldPolicy_KeyArgs = { module FieldPolicy = { type t<'existing> = { - keyArgs: option, - read: option>, - merge: option>, + keyArgs?: FieldPolicy_KeyArgs.t, + read?: FieldReadFunction.t<'existing>, + merge?: FieldMerge.t<'existing>, } module Js_ = { @@ -222,15 +222,15 @@ module FieldPolicy = { // merge?: FieldMergeFunction | boolean; // }; type t<'existing> = { - keyArgs: option, - read: option>, - merge: option>, + keyArgs?: FieldPolicy_KeyArgs.Js_.t, + read?: FieldReadFunction.Js_.t<'existing>, + merge?: FieldMerge.Js_.t<'existing>, } } let toJs: t<'existing> => Js_.t<'existing> = t => { - keyArgs: t.keyArgs->Belt.Option.map(FieldPolicy_KeyArgs.toJs), - read: t.read->Belt.Option.map(FieldReadFunction.toJs), - merge: t.merge->Belt.Option.map(FieldMerge.toJs), + keyArgs: ?t.keyArgs->Belt.Option.map(FieldPolicy_KeyArgs.toJs), + read: ?t.read->Belt.Option.map(FieldReadFunction.toJs), + merge: ?t.merge->Belt.Option.map(FieldMerge.toJs), } } diff --git a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res index 6bb12ad..0ae9516 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res +++ b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res @@ -671,15 +671,15 @@ let make: ( jsClient, ~options=MutationOptions.toJs( { - awaitRefetchQueries, - context, - errorPolicy, - fetchPolicy, + ?awaitRefetchQueries, + ?context, + ?errorPolicy, + ?fetchPolicy, mutation: Operation.query, - optimisticResponse, - updateQueries, - refetchQueries, - update, + ?optimisticResponse, + ?updateQueries, + ?refetchQueries, + ?update, variables, }, ~mapJsVariables, @@ -858,11 +858,11 @@ let make: ( jsClient, ~options=SubscriptionOptions.toJs( { - fetchPolicy, + ?fetchPolicy, query: Operation.query, variables, - errorPolicy, - context, + ?errorPolicy, + ?context, }, ~mapJsVariables, ~serializeVariables=Operation.serializeVariables, diff --git a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res index cf54df3..962df72 100644 --- a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res +++ b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res @@ -231,20 +231,19 @@ module SubscribeToMoreOptions = { document: Graphql.documentNode, // We don't allow optional variables because it's not typesafe variables: 'subscriptionVariables, - updateQuery: option< + updateQuery?: UpdateQueryFn.Js_.t<'jsQueryData, 'subscriptionVariables, 'jsSubscriptionData>, - >, - onError: option unit>, - context: option, + onError?: Js.Exn.t => unit, + context?: Js.Json.t, } } type t<'queryData, 'subscriptionVariables, 'subscriptionData> = { document: Graphql.documentNode, variables: 'subscriptionVariables, - updateQuery: option>, - onError: option unit>, - context: option, + updateQuery?: UpdateQueryFn.t<'queryData, 'subscriptionVariables, 'subscriptionData>, + onError?: Js.Exn.t => unit, + context?: Js.Json.t, } let toJs: ( @@ -262,7 +261,7 @@ module SubscribeToMoreOptions = { ) => { document: t.document, variables: t.variables, - updateQuery: t.updateQuery->Belt.Option.map( + updateQuery: ?t.updateQuery->Belt.Option.map( UpdateQueryFn.toJs( ~onParseError=onUpdateQueryParseError, ~querySafeParse, @@ -270,8 +269,8 @@ module SubscribeToMoreOptions = { ~subscriptionSafeParse, ), ), - onError: t.onError, - context: t.context, + onError: ?t.onError, + context: ?t.context, } } @@ -288,18 +287,18 @@ module SubscriptionOptions = { query: Graphql.documentNode, // We don't allow optional variables because it's not typesafe variables: 'jsVariables, - fetchPolicy: option, - errorPolicy: option, - context: option, + fetchPolicy?: FetchPolicy.Js_.t, + errorPolicy?: ErrorPolicy.Js_.t, + context?: Js.Json.t, } } type t<'variables> = { query: Graphql.documentNode, variables: 'variables, - fetchPolicy: option, - errorPolicy: option, - context: option, + fetchPolicy?: FetchPolicy.t, + errorPolicy?: ErrorPolicy.t, + context?: Js.Json.t, } let toJs: ( @@ -309,9 +308,9 @@ module SubscriptionOptions = { ) => Js_.t<'jsVariables> = (t, ~mapJsVariables, ~serializeVariables) => { query: t.query, variables: t.variables->serializeVariables->mapJsVariables, - fetchPolicy: t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), - errorPolicy: t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - context: t.context, + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + context: ?t.context, } } @@ -371,31 +370,31 @@ module MutationOptions = { // } type t<'jsData, 'jsVariables> = { mutation: Graphql.documentNode, - context: option, - fetchPolicy: option, + context?: Js.Json.t, + fetchPolicy?: FetchPolicy__noCacheExtracted.Js_.t, // ...extends MutationBaseOption, - awaitRefetchQueries: option, - errorPolicy: option, - optimisticResponse: option<(. 'jsVariables) => 'jsData>, - update: option>, - updateQueries: option>, - refetchQueries: option, + awaitRefetchQueries?: bool, + errorPolicy?: ErrorPolicy.Js_.t, + optimisticResponse?: (. 'jsVariables) => 'jsData, + update?: MutationUpdaterFn.Js_.t<'jsData>, + updateQueries?: MutationQueryReducersMap.Js_.t<'jsData>, + refetchQueries?: RefetchQueryDescription.Js_.t, // We don't allow optional variables because it's not typesafe variables: 'jsVariables, } } type t<'data, 'variables, 'jsVariables> = { - context: option, - fetchPolicy: option, + context?: Js.Json.t, + fetchPolicy?: FetchPolicy__noCacheExtracted.t, mutation: Graphql.documentNode, // ...extends MutationBaseOptions, - awaitRefetchQueries: option, - errorPolicy: option, - optimisticResponse: option<'jsVariables => 'data>, - refetchQueries: option, - update: option>, - updateQueries: option>, + awaitRefetchQueries?: bool, + errorPolicy?: ErrorPolicy.t, + optimisticResponse?: 'jsVariables => 'data, + refetchQueries?: RefetchQueryDescription.t, + update?: MutationUpdaterFn.t<'data>, + updateQueries?: MutationQueryReducersMap.t<'data>, variables: 'variables, } @@ -412,17 +411,17 @@ module MutationOptions = { ~serialize, ~serializeVariables, ) => { - awaitRefetchQueries: t.awaitRefetchQueries, - context: t.context, - errorPolicy: t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - fetchPolicy: t.fetchPolicy->Belt.Option.map(FetchPolicy__noCacheExtracted.toJs), + awaitRefetchQueries: ?t.awaitRefetchQueries, + context: ?t.context, + 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 => + 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)), + 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, } } diff --git a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res index 9f90d14..12323e9 100644 --- a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res +++ b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res @@ -35,8 +35,8 @@ module Options = { // } // } type t = { - delay: option, - attempts: option, + delay?: T_delayUnion.t, + attempts?: T_attemptsUnion.t, } } @@ -44,12 +44,12 @@ module Options = { type t_attempts = RetryFunctionOptions(RetryFunctionOptions.t) | RetryFunction(RetryFunction.t) type t = { - delay: option, - attempts: option, + delay?: t_delay, + attempts?: t_attempts, } let toJs: t => Js_.t = t => { - delay: t.delay->Belt.Option.map(delay => + delay: ?t.delay->Belt.Option.map(delay => switch delay { | DelayFunctionOptions(delayFunctionOptions) => Js_.T_delayUnion.delayFunctionOptions(delayFunctionOptions) @@ -57,7 +57,7 @@ module Options = { Js_.T_delayUnion.delayFunction(delayFunction->DelayFunction.toJs) } ), - attempts: t.attempts->Belt.Option.map(attempts => + attempts: ?t.attempts->Belt.Option.map(attempts => switch attempts { | RetryFunctionOptions(retryFunctionOptions) => Js_.T_attemptsUnion.retryFunctionOptions(retryFunctionOptions->RetryFunctionOptions.toJs) @@ -82,7 +82,7 @@ module Js_ = { let make = (~attempts=?, ~delay=?, ()) => Js_.make( Options.toJs({ - attempts: attempts, - delay: delay, + attempts: ?attempts, + delay: ?delay, }), ) diff --git a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseSubscription.res b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseSubscription.res index c3e56d7..15afbcf 100644 --- a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseSubscription.res +++ b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseSubscription.res @@ -72,13 +72,12 @@ let useSubscription: Operation.query, SubscriptionHookOptions.toJs( { - client: client, - fetchPolicy: fetchPolicy, - onSubscriptionData: onSubscriptionData, - onSubscriptionComplete: onSubscriptionComplete, - subscription: None, - shouldResubscribe: shouldResubscribe, - skip: skip, + client: ?client, + fetchPolicy: ?fetchPolicy, + onSubscriptionData: ?onSubscriptionData, + onSubscriptionComplete: ?onSubscriptionComplete, + shouldResubscribe: ?shouldResubscribe, + skip: ?skip, variables: variables, }, ~mapJsVariables, diff --git a/src/@apollo/client/react/types/ApolloClient__React_Types.res b/src/@apollo/client/react/types/ApolloClient__React_Types.res index 4c92dc4..6e852f7 100644 --- a/src/@apollo/client/react/types/ApolloClient__React_Types.res +++ b/src/@apollo/client/react/types/ApolloClient__React_Types.res @@ -465,11 +465,11 @@ module QueryResult = { { document: Operation.query, variables, - updateQuery, - onError: onError->Belt.Option.map((onError, error) => + ?updateQuery, + onError: ?onError->Belt.Option.map((onError, error) => onError(SubscriptionError(error)) ), - context, + ?context, }, ~onUpdateQueryParseError=parseError => switch onError { @@ -866,23 +866,23 @@ module MutationFunctionOptions = { type t<'jsData, 'jsVariables> = { // We don't allow optional variables because it's not typesafe variables: 'jsVariables, - optimisticResponse: option<(. 'jsVariables) => 'jsData>, - refetchQueries: option, - awaitRefetchQueries: option, - update: option>, - context: option, // actual: option(Context) - fetchPolicy: option, + optimisticResponse?: (. 'jsVariables) => 'jsData, + refetchQueries?: RefetchQueryDescription.Js_.t, + awaitRefetchQueries?: bool, + update?: MutationUpdaterFn.Js_.t<'jsData>, + context?: Js.Json.t, // actual: option + fetchPolicy?: WatchQueryFetchPolicy.Js_.t, } } type t<'data, 'variables, 'jsVariables> = { variables: 'variables, - optimisticResponse: option<'jsVariables => 'data>, - refetchQueries: option, - awaitRefetchQueries: option, - update: option>, - context: option, // actual: option(Context) - fetchPolicy: option, + optimisticResponse?: 'jsVariables => 'data, + refetchQueries?: RefetchQueryDescription.t, + awaitRefetchQueries?: bool, + update?: MutationUpdaterFn.t<'data>, + context?: Js.Json.t, // actual: option(Context) + fetchPolicy?: WatchQueryFetchPolicy.t, } let toJs: ( @@ -899,14 +899,14 @@ module MutationFunctionOptions = { ~serializeVariables, ) => { variables: t.variables->serializeVariables->mapJsVariables, - optimisticResponse: t.optimisticResponse->Belt.Option.map(optimisticResponse => + 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)), - context: t.context, - fetchPolicy: t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), + refetchQueries: ?t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs), + awaitRefetchQueries: ?t.awaitRefetchQueries, + update: ?t.update->Belt.Option.map(MutationUpdaterFn.toJs(~safeParse)), + context: ?t.context, + fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), } } @@ -963,12 +963,12 @@ module MutationTuple = { MutationFunctionOptions.toJs( { variables, - optimisticResponse, - refetchQueries, - awaitRefetchQueries, - update, - context, - fetchPolicy, + ?optimisticResponse, + ?refetchQueries, + ?awaitRefetchQueries, + ?update, + ?context, + ?fetchPolicy, }, ~mapJsVariables, ~safeParse, @@ -1040,12 +1040,12 @@ module MutationTuple__noVariables = { MutationFunctionOptions.toJs( { variables, - optimisticResponse, - refetchQueries, - awaitRefetchQueries, - update, - context, - fetchPolicy, + ?optimisticResponse, + ?refetchQueries, + ?awaitRefetchQueries, + ?update, + ?context, + ?fetchPolicy, }, ~mapJsVariables, ~safeParse, @@ -1143,36 +1143,36 @@ module BaseSubscriptionOptions = { // onSubscriptionComplete?: () => void; // } type rec t<'jsData, 'jsVariables> = { - variables: option<'jsVariables>, - fetchPolicy: option, - shouldResubscribe: option<(. t<'jsData, 'jsVariables>) => bool>, - client: option, - skip: option, - onSubscriptionData: option<(. OnSubscriptionDataOptions.Js_.t<'jsData>) => unit>, - onSubscriptionComplete: option unit>, + variables?: 'jsVariables, + fetchPolicy?: FetchPolicy.t, + shouldResubscribe?: (. t<'jsData, 'jsVariables>) => bool, + client?: ApolloClient.t, + skip?: bool, + onSubscriptionData?: (. OnSubscriptionDataOptions.Js_.t<'jsData>) => unit, + onSubscriptionComplete?: unit => unit, } } type rec t<'data, 'jsVariables> = { - variables: option<'jsVariables>, - fetchPolicy: option, - shouldResubscribe: option => bool>, - client: option, - skip: option, - onSubscriptionData: option => unit>, - onSubscriptionComplete: option unit>, + variables?: 'jsVariables, + fetchPolicy?: FetchPolicy.t, + shouldResubscribe?: t<'data, 'jsVariables> => bool, + client?: ApolloClient.t, + skip?: bool, + onSubscriptionData?: OnSubscriptionDataOptions.t<'data> => unit, + onSubscriptionComplete?: unit => unit, } let fromJs: Js_.t<'jsData, 'jsVariables> => t<'data, 'jsVariables> = js => { - variables: js.variables, - fetchPolicy: js.fetchPolicy, + variables: ?js.variables, + fetchPolicy: ?js.fetchPolicy, // shouldResubscribe: what to do here? - shouldResubscribe: Obj.magic(js.shouldResubscribe), - client: js.client, - skip: js.skip, + shouldResubscribe: ?Obj.magic(js.shouldResubscribe), + client: ?js.client, + skip: ?js.skip, // onSubscriptionData: what to do here? - onSubscriptionData: Obj.magic(js.onSubscriptionData), - onSubscriptionComplete: js.onSubscriptionComplete, + onSubscriptionData: ?Obj.magic(js.onSubscriptionData), + onSubscriptionComplete: ?js.onSubscriptionComplete, } } @@ -1196,14 +1196,14 @@ module SubscriptionHookOptions = { } type t<'data, 'variables, 'jsVariables> = { - subscription: option, + subscription?: Graphql.documentNode, variables: 'variables, - fetchPolicy: option, - shouldResubscribe: option => bool>, - client: option, - skip: option, - onSubscriptionData: option => unit>, - onSubscriptionComplete: option unit>, + fetchPolicy?: FetchPolicy.t, + shouldResubscribe?: BaseSubscriptionOptions.t<'data, 'jsVariables> => bool, + client?: ApolloClient.t, + skip?: bool, + onSubscriptionData?: OnSubscriptionDataOptions.t<'data> => unit, + onSubscriptionComplete?: unit => unit, } let toJs: ( diff --git a/src/subscriptions-transport-ws/ApolloClient__SubscriptionsTransportWs.res b/src/subscriptions-transport-ws/ApolloClient__SubscriptionsTransportWs.res index a059733..7629726 100644 --- a/src/subscriptions-transport-ws/ApolloClient__SubscriptionsTransportWs.res +++ b/src/subscriptions-transport-ws/ApolloClient__SubscriptionsTransportWs.res @@ -84,38 +84,39 @@ module ClientOptions = { // inactivityTimeout?: number; // } type t = { - connectionParams: option, - timeout: option, - reconnect: option, - reconnectionAttempts: option, - connectionCallback: option<(~error: array, ~result: option) => unit>, + connectionParams?: ConnectionParamsOptions.Js_.t, + timeout?: int, + reconnect?: bool, + reconnectionAttempts?: int, + connectionCallback?: (~error: array, ~result: option) => unit, @as("lazy") - lazy_: option, - inactivityTimeout: option, + lazy_?: bool, + inactivityTimeout?: int, } } type t = { - connectionParams: option, - timeout: option, - reconnect: option, - reconnectionAttempts: option, - connectionCallback: option<(~error: array, ~result: option) => unit>, + connectionParams?: ConnectionParamsOptions.t, + timeout?: int, + reconnect?: bool, + reconnectionAttempts?: int, + connectionCallback?: (~error: array, ~result: option) => unit, @as("lazy") - lazy_: option, - inactivityTimeout: option, + lazy_?: bool, + inactivityTimeout?: int, } let toJs: t => Js_.t = t => { - connectionParams: t.connectionParams->Belt.Option.map(ConnectionParamsOptions.toJs), - timeout: t.timeout, - reconnect: t.reconnect, - reconnectionAttempts: t.reconnectionAttempts, - connectionCallback: t.connectionCallback, - lazy_: t.lazy_, - inactivityTimeout: t.inactivityTimeout, + connectionParams: ?t.connectionParams->Belt.Option.map(ConnectionParamsOptions.toJs), + timeout: ?t.timeout, + reconnect: ?t.reconnect, + reconnectionAttempts: ?t.reconnectionAttempts, + connectionCallback: ?t.connectionCallback, + lazy_: ?t.lazy_, + inactivityTimeout: ?t.inactivityTimeout, } + @deprecated("Construct the record directly instead") let make = ( ~connectionParams=?, ~timeout=?, @@ -126,13 +127,13 @@ module ClientOptions = { ~inactivityTimeout=?, (), ): t => { - connectionParams: connectionParams, - timeout: timeout, - reconnect: reconnect, - reconnectionAttempts: reconnectionAttempts, - connectionCallback: connectionCallback, - lazy_: lazy_, - inactivityTimeout: inactivityTimeout, + connectionParams: ?connectionParams, + timeout: ?timeout, + reconnect: ?reconnect, + reconnectionAttempts: ?reconnectionAttempts, + connectionCallback: ?connectionCallback, + lazy_: ?lazy_, + inactivityTimeout: ?inactivityTimeout, } } From ce43c2192efd6a53f170239254369711597b686d Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 7 Oct 2024 21:46:11 -0400 Subject: [PATCH 12/16] refactor: uncurries internal functions so that the package can compile on either curried/uncurried However, in usage with @reasonml-community/graphql-ppx, support for curried mode must be broken so that the module types can be updated to uncurried functions and work properly. --- EXAMPLES/bsconfig.json | 2 + EXAMPLES/package.json | 4 +- EXAMPLES/src/caching/LocalStateManagement.res | 2 +- bsconfig.json | 1 + package.json | 10 +- .../core/ApolloClient__Cache_Core_Cache.res | 17 ++- ...loClient__Cache_InMemory_InMemoryCache.res | 2 +- .../ApolloClient__Cache_InMemory_Policies.res | 12 +- ...t__Cache_InMemory_Policies_FieldPolicy.res | 32 +++--- .../core/ApolloClient__Core_ApolloClient.res | 66 +++++------ .../client/core/ApolloClient__Core_Types.res | 10 +- .../ApolloClient__Core_WatchQueryOptions.res | 63 ++++++----- .../ApolloClient__Errors_ApolloError.res | 6 +- .../link/error/ApolloClient__Link_Error.res | 2 +- ...ApolloClient__Link_Retry_DelayFunction.res | 4 +- ...ApolloClient__Link_Retry_RetryFunction.res | 4 +- .../ApolloClient__Link_Retry_RetryLink.res | 4 +- .../client/link/ws/ApolloClient__Link_Ws.res | 2 +- ...ApolloClient__React_Hooks_UseLazyQuery.res | 4 +- .../ApolloClient__React_Hooks_UseMutation.res | 4 +- .../ApolloClient__React_Hooks_UseQuery.res | 2 +- ...lloClient__React_Hooks_UseSubscription.res | 4 +- .../react/types/ApolloClient__React_Types.res | 104 +++++++++--------- ...oClient__Utilities_Policies_Pagination.res | 6 +- src/ApolloClient__Types.res | 2 +- src/ApolloClient__Utils.res | 4 +- ...ApolloClient__SubscriptionsTransportWs.res | 8 +- 27 files changed, 198 insertions(+), 183 deletions(-) diff --git a/EXAMPLES/bsconfig.json b/EXAMPLES/bsconfig.json index f00081a..000df21 100644 --- a/EXAMPLES/bsconfig.json +++ b/EXAMPLES/bsconfig.json @@ -1,7 +1,9 @@ { "name": "examples", + "uncurried": false, "graphql": { "apolloMode": true, + "uncurried": false, "extendMutation": "ApolloClient.GraphQL_PPX.ExtendMutation", "extendQuery": "ApolloClient.GraphQL_PPX.ExtendQuery", "extendSubscription": "ApolloClient.GraphQL_PPX.ExtendSubscription", diff --git a/EXAMPLES/package.json b/EXAMPLES/package.json index cd01690..c12897f 100644 --- a/EXAMPLES/package.json +++ b/EXAMPLES/package.json @@ -10,10 +10,10 @@ "start": "rescript build -with-deps -w" }, "devDependencies": { - "@reasonml-community/graphql-ppx": "1.2.4-1345e061.0", + "@reasonml-community/graphql-ppx": "1.2.4-79d140a5.0", "graphql-client-example-server": "1.5.2", "html-webpack-plugin": "5.5.0", - "rescript": "10.1.2", + "rescript": "11.1.4", "webpack": "5.75.0", "webpack-cli": "5.0.1", "webpack-dev-server": "^4.11.1" diff --git a/EXAMPLES/src/caching/LocalStateManagement.res b/EXAMPLES/src/caching/LocalStateManagement.res index 5b0d003..1efcaeb 100644 --- a/EXAMPLES/src/caching/LocalStateManagement.res +++ b/EXAMPLES/src/caching/LocalStateManagement.res @@ -8,7 +8,7 @@ let cache = { "Query", TypePolicy.make( ~fields=[ - ("someLocalStateField", FieldReadFunction((_existing, _options) => someLocalState())), + ("someLocalStateField", FieldReadFunction((. _existing, _options) => someLocalState())), ], (), ), diff --git a/bsconfig.json b/bsconfig.json index e21f186..f28bec5 100644 --- a/bsconfig.json +++ b/bsconfig.json @@ -1,5 +1,6 @@ { "name": "rescript-apollo-client", + "uncurried": false, "package-specs": [ { "module": "commonjs", diff --git a/package.json b/package.json index 25c879f..c02ed8f 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,9 @@ }, "devDependencies": { "@apollo/client": "^3.5.0", - "@reasonml-community/graphql-ppx": "1.2.4-1345e061.0", + "@reasonml-community/graphql-ppx": "1.2.4-79d140a5.0", "@rescript/react": "~0.11.0", - "rescript": "~10.1.2", + "rescript": "~11.1.4", "graphql": "^15.0.0", "jest": "26.5.3", "react": "^18.2.0", @@ -41,5 +41,9 @@ "rescript": { "optional": true } - } + }, + "workspaces": [ + "./", + "./EXAMPLES" + ] } 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 1a6e86e..32fd354 100644 --- a/src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res +++ b/src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res @@ -181,8 +181,7 @@ module ApolloCache = { ~fragmentName=?, (), ) => { - let safeParse = Utils.safeParse(Fragment.parse) - + let safeParse = Utils.safeParse(. Fragment.parse) js ->Js_.readFragment( ~options={ @@ -196,7 +195,7 @@ module ApolloCache = { (), ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let readQuery = ( @@ -212,7 +211,7 @@ module ApolloCache = { ~canonizeResults=?, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) js ->Js_.readQuery( @@ -230,7 +229,7 @@ module ApolloCache = { ~optimistic, ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let writeFragment = ( @@ -304,7 +303,7 @@ module ApolloCache = { ~update, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) js ->Js_.updateQuery(~options=DataProxy.UpdateQueryOptions.toJs( @@ -328,7 +327,7 @@ module ApolloCache = { ->Js.Nullable.fromOption ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let updateFragment = ( @@ -343,7 +342,7 @@ module ApolloCache = { ~update, (), ) => { - let safeParse = Utils.safeParse(Fragment.parse) + let safeParse = Utils.safeParse(. Fragment.parse) js ->Js_.updateFragment(~options=DataProxy.UpdateFragmentOptions.toJs({ @@ -363,7 +362,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_InMemoryCache.res b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_InMemoryCache.res index 4fbd480..4bcf344 100644 --- a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_InMemoryCache.res +++ b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_InMemoryCache.res @@ -85,5 +85,5 @@ let make: ( ?dataIdFromObject, ?possibleTypes, ?resultCaching, - typePolicies: ?typePolicies->Belt.Option.map(TypePolicies.toJs), + typePolicies: ?typePolicies->Belt.Option.mapU(TypePolicies.toJs), })->ApolloCache.fromJs diff --git a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res index e93a2bf..f17bcfa 100644 --- a/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res +++ b/src/@apollo/client/cache/inmemory/ApolloClient__Cache_InMemory_Policies.res @@ -79,13 +79,13 @@ module TypePolicy = { } let toJs: (. t) => Js_.t = (. t) => { - keyFields: ?t.keyFields->Belt.Option.map(KeyArgs.toJs), + keyFields: ?t.keyFields->Belt.Option.mapU(KeyArgs.toJs), queryType: ?t.queryType, mutationType: ?t.mutationType, subscriptionType: ?t.subscriptionType, - fields: ?t.fields->Belt.Option.map(fields => + fields: ?t.fields->Belt.Option.mapU((. fields) => fields - ->Belt.Array.map(((fieldKey, t_field)) => ( + ->Belt.Array.mapU((. (fieldKey, t_field)) => ( fieldKey, switch t_field { | ConcatPagination(keyArgs) => @@ -97,7 +97,7 @@ module TypePolicy = { | FieldPolicy(fieldPolicy) => fieldPolicy->FieldPolicy.toJs->Js_.FieldsUnion.fieldPolicy | FieldReadFunction(fieldReadFunction) => - fieldReadFunction->FieldReadFunction.toJs->Js_.FieldsUnion.fieldReadFunction + FieldReadFunction.toJs(. fieldReadFunction)->Js_.FieldsUnion.fieldReadFunction }, )) ->Js.Dict.fromArray @@ -133,8 +133,8 @@ module TypePolicies = { type t = array<(typename, TypePolicy.t)> - let toJs: t => Js_.t = t => - t->Belt.Array.map(((key, policy)) => (key, TypePolicy.toJs(. policy)))->Js.Dict.fromArray + let toJs: (. t) => Js_.t = (. t) => + t->Belt.Array.mapU((. (key, policy)) => (key, TypePolicy.toJs(. policy)))->Js.Dict.fromArray } module PossibleTypesMap = { 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 3668043..c43c136 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 @@ -100,11 +100,12 @@ module FieldMergeFunction = { // incoming: SafeReadonly, // options: TOptions, // ) => SafeReadonly; - type t<'existing> = ('existing, 'existing, FieldFunctionOptions.Js_.t) => 'existing + type t<'existing> = (. 'existing, 'existing, FieldFunctionOptions.Js_.t) => 'existing } - let toJs: t<'existing> => Js_.t<'existing> = (t, existing, incoming, jsFieldFunctionOptions) => - t(existing, incoming, jsFieldFunctionOptions->FieldFunctionOptions.fromJs) + let toJs: (. t<'existing>) => Js_.t<'existing> = (. t) => + (. existing, incoming, jsFieldFunctionOptions) => + t(existing, incoming, jsFieldFunctionOptions->FieldFunctionOptions.fromJs) } module FieldMerge = { @@ -116,36 +117,37 @@ module FieldMerge = { // FieldMergeFunction | boolean; module FieldMergeUnion: { type t<'existing> - let mergeFunction: FieldMergeFunction.Js_.t<'existing> => t<'existing> + let mergeFunction: (. FieldMergeFunction.Js_.t<'existing>) => t<'existing> let true_: t<'existing> } = { @unboxed type rec t<'existing> = Any('a): t<'existing> - let mergeFunction = (v: FieldMergeFunction.Js_.t<'existing>) => Any(v) + let mergeFunction = (. v: FieldMergeFunction.Js_.t<'existing>) => Any(v) let true_ = Any(true) } type t<'existing> = FieldMergeUnion.t<'existing> } - let toJs: t<'existing> => Js_.t<'existing> = x => + let toJs: (. t<'existing>) => Js_.t<'existing> = (. x) => switch x { | MergeFunction(mergeFunction) => - mergeFunction->FieldMergeFunction.toJs->Js_.FieldMergeUnion.mergeFunction + Js_.FieldMergeUnion.mergeFunction(. mergeFunction->FieldMergeFunction.toJs) | True => Js_.FieldMergeUnion.true_ } } module FieldReadFunction = { - type t<'existing> = (option<'existing>, FieldFunctionOptions.t) => 'existing + type t<'existing> = (. option<'existing>, FieldFunctionOptions.t) => 'existing module Js_ = { // export declare type FieldReadFunction = (existing: SafeReadonly | undefined, options: FieldFunctionOptions) => TReadResult | undefined; - type t<'existing> = (option<'existing>, FieldFunctionOptions.Js_.t) => 'existing + type t<'existing> = (. option<'existing>, FieldFunctionOptions.Js_.t) => 'existing } - let toJs: t<'existing> => Js_.t<'existing> = (t, existing, jsFieldFunctionOptions) => - t(existing, jsFieldFunctionOptions->FieldFunctionOptions.fromJs) + let toJs: (. t<'existing>) => Js_.t<'existing> = (. t) => + (. existing, jsFieldFunctionOptions) => + t(. existing, jsFieldFunctionOptions->FieldFunctionOptions.fromJs) } module KeySpecifier = { @@ -200,7 +202,7 @@ module FieldPolicy_KeyArgs = { type t = KeyArgsUnion.t } - let toJs: t => Js_.t = x => + let toJs: (. t) => Js_.t = (. x) => switch x { | KeySpecifier(keySpecifier) => keySpecifier->Js_.KeyArgsUnion.keySpecifier | KeyArgsFunction(keyArgsFunction) => keyArgsFunction->Js_.KeyArgsUnion.keyArgsFunction @@ -229,8 +231,8 @@ module FieldPolicy = { } let toJs: t<'existing> => Js_.t<'existing> = t => { - keyArgs: ?t.keyArgs->Belt.Option.map(FieldPolicy_KeyArgs.toJs), - read: ?t.read->Belt.Option.map(FieldReadFunction.toJs), - merge: ?t.merge->Belt.Option.map(FieldMerge.toJs), + keyArgs: ?t.keyArgs->Belt.Option.mapU(FieldPolicy_KeyArgs.toJs), + read: ?t.read->Belt.Option.mapU(FieldReadFunction.toJs), + merge: ?t.merge->Belt.Option.mapU(FieldMerge.toJs), } } diff --git a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res index 0ae9516..39d5185 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res +++ b/src/@apollo/client/core/ApolloClient__Core_ApolloClient.res @@ -47,9 +47,9 @@ module DefaultWatchQueryOptions = { context?: Js.Json.t, } - let toJs: t => Js_.t = t => { - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), - errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + let toJs: (. t) => Js_.t = (. t) => { + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(WatchQueryFetchPolicy.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), context: ?t.context, } @@ -79,13 +79,13 @@ module DefaultQueryOptions = { context?: Js.Json.t, } - let toJs: t => Js_.t = t => { + let toJs: (. t) => Js_.t = (. t) => { fetchPolicy: ?switch t.fetchPolicy { - | Some(fetchPolicy) => FetchPolicy.toJs(fetchPolicy)->Some + | Some(fetchPolicy) => FetchPolicy.toJs(. fetchPolicy)->Some | None => None }, errorPolicy: ?switch t.errorPolicy { - | Some(errorPolicy) => ErrorPolicy.toJs(errorPolicy)->Some + | Some(errorPolicy) => ErrorPolicy.toJs(. errorPolicy)->Some | None => None }, context: ?t.context, @@ -123,12 +123,12 @@ module DefaultMutateOptions = { refetchQueries?: RefetchQueryDescription.t, } - let toJs: t => Js_.t = t => { + let toJs: (. t) => Js_.t = (. t) => { context: ?t.context, - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy__noCacheExtracted.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(FetchPolicy__noCacheExtracted.toJs), awaitRefetchQueries: ?t.awaitRefetchQueries, - errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - refetchQueries: ?t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), + refetchQueries: ?t.refetchQueries->Belt.Option.mapU(RefetchQueryDescription.toJs), } @deprecated("Just construct instead") @@ -168,10 +168,10 @@ module DefaultOptions = { mutate?: DefaultMutateOptions.t, } - let toJs: t => Js_.t = t => { - watchQuery: ?t.watchQuery->Belt.Option.map(DefaultWatchQueryOptions.toJs), - query: ?t.query->Belt.Option.map(DefaultQueryOptions.toJs), - mutate: ?t.mutate->Belt.Option.map(DefaultMutateOptions.toJs), + let toJs: (. t) => Js_.t = (. t) => { + watchQuery: ?t.watchQuery->Belt.Option.mapU(DefaultWatchQueryOptions.toJs), + query: ?t.query->Belt.Option.mapU(DefaultQueryOptions.toJs), + mutate: ?t.mutate->Belt.Option.mapU(DefaultMutateOptions.toJs), } @deprecated("Just construct instead") @@ -256,7 +256,7 @@ module ApolloClientOptions = { ssrMode: ?t.ssrMode, connectToDevTools: ?t.connectToDevTools, queryDeduplication: ?t.queryDeduplication, - defaultOptions: ?t.defaultOptions->Belt.Option.map(DefaultOptions.toJs), + defaultOptions: ?t.defaultOptions->Belt.Option.mapU(DefaultOptions.toJs), assumeImmutableResults: ?t.assumeImmutableResults, resolvers: ?t.resolvers, typeDefs: ?t.typeDefs, @@ -328,11 +328,11 @@ module Js_ = { // onClearStore(cb: () => Promise): () => void; @send - external onClearStore: (t, ~cb: unit => Js.Promise.t, unit) => unit = "onClearStore" + external onClearStore: (t, ~cb: unit => Js.Promise.t) => 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 = "onResetStore" // query(options: QueryOptions): Promise>; @send @@ -446,9 +446,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, @as("rescript_onResetStore") - onResetStore: (~cb: unit => Js.Promise.t, unit) => unit, + onResetStore: (~cb: unit => Js.Promise.t) => unit, @as("rescript_query") query: 'data 'variables 'jsVariables. ( ~query: module(Operation with @@ -665,7 +665,7 @@ let make: ( ~update=?, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) Js_.mutate( jsClient, @@ -725,7 +725,7 @@ let make: ( ~mapJsVariables=Utils.identity, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) Js_.query( jsClient, @@ -772,7 +772,7 @@ let make: ( ~fragmentName=?, (), ) => { - let safeParse = Utils.safeParse(Fragment.parse) + let safeParse = Utils.safeParse(. Fragment.parse) jsClient ->Js_.readFragment( @@ -787,7 +787,7 @@ let make: ( (), ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let readQuery = ( @@ -803,7 +803,7 @@ let make: ( ~canonizeResults=?, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) Js_.readQuery( jsClient, @@ -821,7 +821,7 @@ let make: ( ~optimistic, ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let resetStore: unit => Js.Promise.t< @@ -852,7 +852,7 @@ let make: ( ~mapJsVariables=Utils.identity, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) let jsObservable = Js_.subscribe( jsClient, @@ -881,9 +881,9 @@ let make: ( } } - let onError' = onError->Belt.Option.map(onError => { + let onError' = onError->Belt.Option.mapU((. onError) => { let return = unknown => - Obj.magic(unknown)->ApolloError.Js_.ensureApolloError->ApolloError.fromJs->onError + Obj.magic(unknown)->ApolloError.Js_.ensureApolloError->ApolloError.fromJs(. _)->onError return }) @@ -908,7 +908,7 @@ let make: ( ~pollInterval=?, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) jsClient ->Js_.watchQuery( @@ -999,7 +999,7 @@ let make: ( ~update, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) jsClient ->Js_.updateQuery( @@ -1025,7 +1025,7 @@ let make: ( ->Js.Nullable.fromOption, ) ->Js.toOption - ->Belt.Option.map(safeParse) + ->Belt.Option.mapU(safeParse) } let updateFragment = ( @@ -1040,7 +1040,7 @@ let make: ( ~update, (), ) => { - let safeParse = Utils.safeParse(Fragment.parse) + let safeParse = Utils.safeParse(. Fragment.parse) jsClient ->Js_.updateFragment( @@ -1062,7 +1062,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 dffa03e..67f5dd6 100644 --- a/src/@apollo/client/core/ApolloClient__Core_Types.res +++ b/src/@apollo/client/core/ApolloClient__Core_Types.res @@ -147,12 +147,12 @@ module MutationQueryReducer = { type t<'data> = (Js.Json.t, options<'data>) => Js.Json.t - let toJs: ( + let toJs: (. t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>, - . Js.Json.t, + Js.Json.t, Js_.options<'jsData>, - ) => Js.Json.t = (t, ~safeParse, . previousResult, jsOptions) => + ) => Js.Json.t = (. t, ~safeParse, previousResult, jsOptions) => t( previousResult, { @@ -175,12 +175,12 @@ module MutationQueryReducersMap = { type t<'data> = Js.Dict.t> - let toJs: (t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>) => Js_.t<'jsData> = ( + let toJs: (. t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>) => Js_.t<'jsData> = (. t, ~safeParse, ) => Js.Dict.map( - (. mutationQueryReducer) => mutationQueryReducer->MutationQueryReducer.toJs(~safeParse), + (. mutationQueryReducer) => (. json, options) => MutationQueryReducer.toJs(. mutationQueryReducer, ~safeParse, json, options), t, ) } diff --git a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res index 962df72..865b3da 100644 --- a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res +++ b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res @@ -16,7 +16,7 @@ module ErrorPolicy = { | Ignore | All - let toJs = x => + let toJs = (. x) => switch x { | None => #none | Ignore => #ignore @@ -37,7 +37,7 @@ module FetchPolicy = { | NoCache | Standby - let toJs = (x): Js_.t => + let toJs = (. x): Js_.t => switch x { | CacheFirst => #"cache-first" | CacheOnly => #"cache-only" @@ -54,7 +54,7 @@ module FetchPolicy__noCacheExtracted = { } type t = NoCache - let toJs = x => + let toJs = (. x) => switch x { | NoCache => "no-cache" } @@ -74,7 +74,7 @@ module WatchQueryFetchPolicy = { | NoCache | Standby - let toJs = (x): Js_.t => + let toJs = (. x): Js_.t => switch x { | CacheAndNetwork => #"cache-and-network" | CacheFirst => #"cache-first" @@ -111,10 +111,10 @@ module QueryOptions = { ~mapJsVariables: 'jsVariables => 'jsVariables, ~serializeVariables: 'variables => 'jsVariables, ) => Js_.t<'jsVariables> = (t, ~mapJsVariables, ~serializeVariables) => { - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(FetchPolicy.toJs), query: t.query, variables: t.variables->serializeVariables->mapJsVariables, - errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), context: ?t.context, } } @@ -149,11 +149,11 @@ module WatchQueryOptions = { ~mapJsVariables: 'jsVariables => 'jsVariables, ~serializeVariables: 'variables => 'jsVariables, ) => Js_.t<'jsVariables> = (t, ~mapJsVariables, ~serializeVariables) => { - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), - nextFetchPolicy: ?t.nextFetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(WatchQueryFetchPolicy.toJs), + nextFetchPolicy: ?t.nextFetchPolicy->Belt.Option.mapU(WatchQueryFetchPolicy.toJs), query: t.query, variables: t.variables->serializeVariables->mapJsVariables, - errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), context: ?t.context, pollInterval: ?t.pollInterval, } @@ -231,8 +231,7 @@ module SubscribeToMoreOptions = { document: Graphql.documentNode, // We don't allow optional variables because it's not typesafe variables: 'subscriptionVariables, - updateQuery?: - UpdateQueryFn.Js_.t<'jsQueryData, 'subscriptionVariables, 'jsSubscriptionData>, + updateQuery?: UpdateQueryFn.Js_.t<'jsQueryData, 'subscriptionVariables, 'jsSubscriptionData>, onError?: Js.Exn.t => unit, context?: Js.Json.t, } @@ -261,13 +260,14 @@ module SubscribeToMoreOptions = { ) => { document: t.document, variables: t.variables, - updateQuery: ?t.updateQuery->Belt.Option.map( + updateQuery: ?t.updateQuery->Belt.Option.mapU((. onUpdateQueryFn) => UpdateQueryFn.toJs( + onUpdateQueryFn, ~onParseError=onUpdateQueryParseError, ~querySafeParse, ~querySerialize, ~subscriptionSafeParse, - ), + ) ), onError: ?t.onError, context: ?t.context, @@ -308,8 +308,8 @@ module SubscriptionOptions = { ) => Js_.t<'jsVariables> = (t, ~mapJsVariables, ~serializeVariables) => { query: t.query, variables: t.variables->serializeVariables->mapJsVariables, - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), - errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(FetchPolicy.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), context: ?t.context, } } @@ -321,12 +321,12 @@ module MutationUpdaterFn = { type t<'data> = (ApolloCache.t, FetchResult.t<'data>) => unit - let toJs: (t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>) => Js_.t<'jsData> = ( + let toJs: (. t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>) => Js_.t<'jsData> = (. mutationUpdaterFn, ~safeParse, ) => (. cache, jsFetchResult) => - mutationUpdaterFn(cache, jsFetchResult->FetchResult.fromJs(~safeParse)) + mutationUpdaterFn(cache, FetchResult.fromJs(jsFetchResult, ~safeParse)) } module RefetchQueryDescription = { @@ -351,12 +351,13 @@ module RefetchQueryDescription = { type t = array - let toJs: t => Js_.t = Belt.Array.map(_, x => - switch x { - | PureQueryOptions(options) => Js_.Union.pureQueryOptions(options->PureQueryOptions.toJs) - | String(string) => Js_.Union.string(string) - } - ) + let toJs: (. t) => Js_.t = (. arr) => + Belt.Array.mapU(arr, (. x) => + switch x { + | PureQueryOptions(options) => Js_.Union.pureQueryOptions(options->PureQueryOptions.toJs) + | String(string) => Js_.Union.string(string) + } + ) } module MutationOptions = { @@ -413,15 +414,19 @@ module MutationOptions = { ) => { awaitRefetchQueries: ?t.awaitRefetchQueries, context: ?t.context, - errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy__noCacheExtracted.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(FetchPolicy__noCacheExtracted.toJs), mutation: t.mutation, - optimisticResponse: ?t.optimisticResponse->Belt.Option.map(optimisticResponse => + optimisticResponse: ?t.optimisticResponse->Belt.Option.mapU((. 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)), + refetchQueries: ?t.refetchQueries->Belt.Option.mapU(RefetchQueryDescription.toJs), + update: ?t.update->Belt.Option.mapU((. updater) => + MutationUpdaterFn.toJs(. updater, ~safeParse) + ), + updateQueries: ?t.updateQueries->Belt.Option.mapU((. data) => + MutationQueryReducersMap.toJs(. data, ~safeParse) + ), variables: t.variables->serializeVariables->mapJsVariables, } } diff --git a/src/@apollo/client/errors/ApolloClient__Errors_ApolloError.res b/src/@apollo/client/errors/ApolloClient__Errors_ApolloError.res index bf84102..a8b7093 100644 --- a/src/@apollo/client/errors/ApolloClient__Errors_ApolloError.res +++ b/src/@apollo/client/errors/ApolloClient__Errors_ApolloError.res @@ -133,14 +133,14 @@ type t = { stack: option, } -let fromJs: Js_.t => t = untrustedJs => { +let fromJs: (. Js_.t) => t = (. untrustedJs) => { let js = Js_.ensureApolloError(untrustedJs) { extraInfo: js.extraInfo, graphQLErrors: js.graphQLErrors->Belt.Option.getWithDefault([]), networkError: js.networkError ->Js.toOption - ->Belt.Option.map(networkError => + ->Belt.Option.mapU((. networkError) => switch networkError->Js_.NetworkErrorUnion.classify { | Error(error) => FetchFailure(error) | ServerError(error) => BadStatus(error.statusCode, error) @@ -165,7 +165,7 @@ let make: ( networkError: Js.Nullable.undefined, errorMessage, extraInfo, - })->fromJs + })->fromJs(. _) {...errorWithoutNetworkError, networkError} } diff --git a/src/@apollo/client/link/error/ApolloClient__Link_Error.res b/src/@apollo/client/link/error/ApolloClient__Link_Error.res index 65416a2..f7628fd 100644 --- a/src/@apollo/client/link/error/ApolloClient__Link_Error.res +++ b/src/@apollo/client/link/error/ApolloClient__Link_Error.res @@ -85,7 +85,7 @@ module ErrorResponse = { let fromJs: Js_.t => t = js => { graphQLErrors: js.graphQLErrors, - networkError: js.networkError->Belt.Option.map(networkError => + networkError: js.networkError->Belt.Option.mapU((. networkError) => switch networkError->Js_.NetworkErrorUnion.classify { | Error(error) => FetchFailure(error) | ServerError(error) => BadStatus(error.statusCode, error) 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 bcaf0bd..0a88cdf 100644 --- a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_DelayFunction.res +++ b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_DelayFunction.res @@ -5,12 +5,12 @@ module DelayFunction = { // export interface DelayFunction { // (count: number, operation: Operation, error: any): number; // } - type t = (int, Operation.Js_.t, option) => int + type t = (. int, Operation.Js_.t, option) => int } 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 e68df29..c6be9a1 100644 --- a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryFunction.res +++ b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryFunction.res @@ -5,12 +5,12 @@ module RetryFunction = { // export interface RetryFunction { // (count: number, operation: Operation, error: any): boolean | Promise; // } - type t = (int, Operation.Js_.t, option) => Js.Promise.t + type t = (. int, Operation.Js_.t, option) => Js.Promise.t } 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/link/retry/ApolloClient__Link_Retry_RetryLink.res b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res index 12323e9..99934a0 100644 --- a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res +++ b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res @@ -49,7 +49,7 @@ module Options = { } let toJs: t => Js_.t = t => { - delay: ?t.delay->Belt.Option.map(delay => + delay: ?t.delay->Belt.Option.mapU((. delay) => switch delay { | DelayFunctionOptions(delayFunctionOptions) => Js_.T_delayUnion.delayFunctionOptions(delayFunctionOptions) @@ -57,7 +57,7 @@ module Options = { Js_.T_delayUnion.delayFunction(delayFunction->DelayFunction.toJs) } ), - attempts: ?t.attempts->Belt.Option.map(attempts => + attempts: ?t.attempts->Belt.Option.mapU((. attempts) => switch attempts { | RetryFunctionOptions(retryFunctionOptions) => Js_.T_attemptsUnion.retryFunctionOptions(retryFunctionOptions->RetryFunctionOptions.toJs) diff --git a/src/@apollo/client/link/ws/ApolloClient__Link_Ws.res b/src/@apollo/client/link/ws/ApolloClient__Link_Ws.res index 9c010df..ab238f0 100644 --- a/src/@apollo/client/link/ws/ApolloClient__Link_Ws.res +++ b/src/@apollo/client/link/ws/ApolloClient__Link_Ws.res @@ -50,7 +50,7 @@ module WebSocketLink = { Js_.make( #Configuration({ uri: uri, - options: options->Belt.Option.map(ClientOptions.toJs), + options: options->Belt.Option.mapU(ClientOptions.toJs), webSocketImpl: webSocketImpl, }), ) diff --git a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseLazyQuery.res b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseLazyQuery.res index 0515b03..e430778 100644 --- a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseLazyQuery.res +++ b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseLazyQuery.res @@ -59,7 +59,7 @@ let useLazyQuery: ~ssr=?, (), ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) let jsQueryTuple = Js_.useLazyQuery(. Operation.query, LazyQueryHookOptions.toJs( @@ -133,7 +133,7 @@ let useLazyQueryWithVariables: ~ssr=?, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) let jsQueryTuple = Js_.useLazyQuery(. Operation.query, diff --git a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseMutation.res b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseMutation.res index 6cdbe10..5ef298a 100644 --- a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseMutation.res +++ b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseMutation.res @@ -61,7 +61,7 @@ let useMutation: ~update=?, (), ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) let jsMutationTuple = Js_.useMutation(. Operation.query, @@ -139,7 +139,7 @@ let useMutationWithVariables: ~update=?, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) let jsMutationTuple = Js_.useMutation(. Operation.query, diff --git a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res index e6d3f79..fa572ab 100644 --- a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res +++ b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.res @@ -63,7 +63,7 @@ let useQuery: ~ssr=?, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) let jsQueryResult = Js_.useQuery(. Operation.query, diff --git a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseSubscription.res b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseSubscription.res index 15afbcf..d5e494e 100644 --- a/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseSubscription.res +++ b/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseSubscription.res @@ -66,7 +66,7 @@ let useSubscription: ~skip=?, variables, ) => { - let safeParse = Utils.safeParse(Operation.parse) + let safeParse = Utils.safeParse(. Operation.parse) let jsSubscriptionResult = Js_.useSubscription(. Operation.query, @@ -90,7 +90,7 @@ let useSubscription: variables: jsSubscriptionResult.variables, loading: jsSubscriptionResult.loading, data: jsSubscriptionResult.data->Belt.Option.map(Operation.parse), - error: jsSubscriptionResult.error->Belt.Option.map(ApolloError.fromJs), + error: jsSubscriptionResult.error->Belt.Option.mapU(ApolloError.fromJs), }, jsSubscriptionResult) } diff --git a/src/@apollo/client/react/types/ApolloClient__React_Types.res b/src/@apollo/client/react/types/ApolloClient__React_Types.res index 6e852f7..f89af63 100644 --- a/src/@apollo/client/react/types/ApolloClient__React_Types.res +++ b/src/@apollo/client/react/types/ApolloClient__React_Types.res @@ -27,7 +27,7 @@ module QueryHookOptions = { // ...extends QueryFunctionOptions displayName?: string, skip?: bool, - onCompleted?: 'jsData => unit, + onCompleted?: (. 'jsData) => unit, onError?: (. ApolloError.Js_.t) => unit, // ..extends BaseQueryOptions client?: ApolloClient.t, @@ -77,15 +77,15 @@ module QueryHookOptions = { client: ?t.client, 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 + errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), + onCompleted: ?t.onCompleted->Belt.Option.mapU((. onCompleted) => + (. jsData) => safeParse(jsData)->onCompleted ), - onError: ?t.onError->Belt.Option.map(onError => - (. jsApolloError) => onError(ApolloError.fromJs(jsApolloError)) + onError: ?t.onError->Belt.Option.mapU((. onError) => + (. jsApolloError) => ApolloError.fromJs(. jsApolloError)->onError ), - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), - nextFetchPolicy: ?t.nextFetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(WatchQueryFetchPolicy.toJs), + nextFetchPolicy: ?t.nextFetchPolicy->Belt.Option.mapU(WatchQueryFetchPolicy.toJs), notifyOnNetworkStatusChange: ?t.notifyOnNetworkStatusChange, query: ?t.query, pollInterval: ?t.pollInterval, @@ -106,7 +106,7 @@ module LazyQueryHookOptions = { query?: Graphql.documentNode, // ...extends QueryFunctionOptions displayName?: string, - onCompleted?: 'jsData => unit, + onCompleted?: (. 'jsData) => unit, onError?: (. ApolloError.Js_.t) => unit, // ..extends BaseQueryOptions client?: ApolloClient.t, @@ -153,23 +153,23 @@ module LazyQueryHookOptions = { client: ?t.client, 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) + errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), + onCompleted: ?t.onCompleted->Belt.Option.mapU((. onCompleted) => + (. jsData) => safeParse(jsData)->onCompleted ), - onError: ?t.onError->Belt.Option.map(onError => - (. jsApolloError) => onError(ApolloError.fromJs(jsApolloError)) + onError: ?t.onError->Belt.Option.mapU((. onError) => + (. jsApolloError) => ApolloError.fromJs(. jsApolloError)->onError ), - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(WatchQueryFetchPolicy.toJs), notifyOnNetworkStatusChange: ?t.notifyOnNetworkStatusChange, query: ?t.query, pollInterval: ?t.pollInterval, partialRefetch: ?t.partialRefetch, ssr: ?t.ssr, variables: ?switch t.variables { - | Some(variables) => serializeVariables(variables)->Some - | None => None - } + | Some(variables) => serializeVariables(variables)->Some + | None => None + }, } } @@ -349,11 +349,11 @@ module QueryResult = { ) => { let (data, error) = Utils.safeParseAndLiftToCommonResultProps( ~jsData=js.data, - ~apolloError=?js.error->Belt.Option.map(ApolloError.fromJs), + ~apolloError=?js.error->Belt.Option.mapU(ApolloError.fromJs), safeParse, ) - let previousData = js.previousData->Belt.Option.map(safeParse) + let previousData = js.previousData->Belt.Option.mapU(safeParse) let fetchMore = ( ~context=?, @@ -367,14 +367,14 @@ module QueryResult = { js ->Js_.fetchMore({ ?context, - updateQuery: ?updateQuery->Belt.Option.map(updateQuery => + updateQuery: ?updateQuery->Belt.Option.mapU((. 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( @@ -398,7 +398,7 @@ module QueryResult = { previousResult } ), - variables: ?variables->Belt.Option.map(v => v->serializeVariables->mapJsVariables), + variables: ?variables->Belt.Option.mapU((. v) => v->serializeVariables->mapJsVariables), }) ->Js.Promise.then_(jsApolloQueryResult => Js.Promise.resolve( @@ -427,7 +427,7 @@ module QueryResult = { let refetch = (~mapJsVariables=Utils.identity, ~variables=?, ()) => js - ->Js_.refetch(variables->Belt.Option.map(v => v->serializeVariables->mapJsVariables)) + ->Js_.refetch(variables->Belt.Option.mapU((. v) => v->serializeVariables->mapJsVariables)) ->Js.Promise.then_( jsApolloQueryResult => Js.Promise.resolve( @@ -458,7 +458,7 @@ module QueryResult = { ~context=?, variables, ) => { - let subscriptionSafeParse = Utils.safeParse(Operation.parse) + let subscriptionSafeParse = Utils.safeParse(. Operation.parse) js->Js_.subscribeToMore( SubscribeToMoreOptions.toJs( @@ -466,9 +466,10 @@ module QueryResult = { document: Operation.query, variables, ?updateQuery, - onError: ?onError->Belt.Option.map((onError, error) => - onError(SubscriptionError(error)) - ), + onError: ?switch onError { + | Some(onError) => Some(error => onError(SubscriptionError(error))) + | None => None + }, ?context, }, ~onUpdateQueryParseError=parseError => @@ -702,7 +703,7 @@ module BaseMutationOptions = { notifyOnNetworkStatusChange: option, onError: option unit>, onCompleted: 'jsData => unit, - optimisticResponse: option<'jsVariables => 'jsData>, + optimisticResponse: option<(. 'jsVariables) => 'jsData>, refetchQueries: option, update: option>, variables: option<'jsVariables>, @@ -742,7 +743,7 @@ module MutationHookOptions = { ignoreResults?: bool, notifyOnNetworkStatusChange?: bool, onError?: (. ApolloError.Js_.t) => unit, - onCompleted?: 'jsData => unit, + onCompleted?: (. 'jsData) => unit, optimisticResponse?: 'jsVariables => 'jsData, refetchQueries?: RefetchQueryDescription.Js_.t, update?: MutationUpdaterFn.Js_.t<'jsData>, @@ -783,23 +784,24 @@ module MutationHookOptions = { awaitRefetchQueries: ?t.awaitRefetchQueries, context: ?t.context, client: ?t.client, - errorPolicy: ?t.errorPolicy->Belt.Option.map(ErrorPolicy.toJs), - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy__noCacheExtracted.toJs), + errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(FetchPolicy__noCacheExtracted.toJs), ignoreResults: ?t.ignoreResults, mutation: ?t.mutation, notifyOnNetworkStatusChange: ?t.notifyOnNetworkStatusChange, - 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.mapU((. onError) => + (. jsApolloError) => onError(ApolloError.fromJs(. jsApolloError)) ), - optimisticResponse: ?t.optimisticResponse->Belt.Option.map((optimisticResponse, variables) => - optimisticResponse(variables)->serialize + onCompleted: ?t.onCompleted->Belt.Option.mapU((. onCompleted) => + (. jsData) => jsData->safeParse->onCompleted ), - refetchQueries: ?t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs), - update: ?t.update->Belt.Option.map(MutationUpdaterFn.toJs(~safeParse)), - variables: ?t.variables->Belt.Option.map(v => v->serializeVariables->mapJsVariables), + 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), } } @@ -838,7 +840,7 @@ module MutationResult = { ) => { let (data, error) = Utils.safeParseAndLiftToCommonResultProps( ~jsData=js.data->Js.toOption, - ~apolloError=?js.error->Belt.Option.map(ApolloError.fromJs), + ~apolloError=?js.error->Belt.Option.mapU(ApolloError.fromJs), safeParse, ) { @@ -899,14 +901,14 @@ module MutationFunctionOptions = { ~serializeVariables, ) => { variables: t.variables->serializeVariables->mapJsVariables, - optimisticResponse: ?t.optimisticResponse->Belt.Option.map(optimisticResponse => + optimisticResponse: ?t.optimisticResponse->Belt.Option.mapU((. optimisticResponse) => (. variables) => optimisticResponse(variables)->serialize ), - refetchQueries: ?t.refetchQueries->Belt.Option.map(RefetchQueryDescription.toJs), + refetchQueries: ?t.refetchQueries->Belt.Option.mapU(RefetchQueryDescription.toJs), awaitRefetchQueries: ?t.awaitRefetchQueries, - update: ?t.update->Belt.Option.map(MutationUpdaterFn.toJs(~safeParse)), + update: ?t.update->Belt.Option.mapU((. updater) => MutationUpdaterFn.toJs(updater, ~safeParse)), context: ?t.context, - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(WatchQueryFetchPolicy.toJs), + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(WatchQueryFetchPolicy.toJs), } } @@ -1097,7 +1099,7 @@ module SubscriptionResult = { ) => { let (data, error) = Utils.safeParseAndLiftToCommonResultProps( ~jsData=js.data, - ~apolloError=?js.error->Belt.Option.map(ApolloError.fromJs), + ~apolloError=?js.error->Belt.Option.mapU(ApolloError.fromJs), safeParse, ) @@ -1214,14 +1216,14 @@ module SubscriptionHookOptions = { ) => Js_.t<'jsData, 'jsVariables> = (t, ~mapJsVariables, ~safeParse, ~serializeVariables) => { subscription: ?t.subscription, variables: t.variables->serializeVariables->mapJsVariables, - fetchPolicy: ?t.fetchPolicy->Belt.Option.map(FetchPolicy.toJs), - shouldResubscribe: ?t.shouldResubscribe->Belt.Option.map(shouldResubscribe => + fetchPolicy: ?t.fetchPolicy->Belt.Option.mapU(FetchPolicy.toJs), + shouldResubscribe: ?t.shouldResubscribe->Belt.Option.mapU((. shouldResubscribe) => (. jsBaseSubscriptionOptions) => shouldResubscribe(jsBaseSubscriptionOptions->BaseSubscriptionOptions.fromJs) ), client: ?t.client, skip: ?t.skip, - onSubscriptionData: ?t.onSubscriptionData->Belt.Option.map(onSubscriptionData => + onSubscriptionData: ?t.onSubscriptionData->Belt.Option.mapU((. onSubscriptionData) => (. jsOnSubscriptionDataOptions) => onSubscriptionData( jsOnSubscriptionDataOptions->OnSubscriptionDataOptions.fromJs(~safeParse), diff --git a/src/@apollo/client/utilities/policies/ApolloClient__Utilities_Policies_Pagination.res b/src/@apollo/client/utilities/policies/ApolloClient__Utilities_Policies_Pagination.res index 63fe641..ad264ff 100644 --- a/src/@apollo/client/utilities/policies/ApolloClient__Utilities_Policies_Pagination.res +++ b/src/@apollo/client/utilities/policies/ApolloClient__Utilities_Policies_Pagination.res @@ -32,10 +32,10 @@ module Js_ = { } let concatPagination: KeyArgs.t => FieldPolicy.Js_.t<'existing> = keyArgs => - Js_.concatPagination(. Some(keyArgs->KeyArgs.toJs)) + Js_.concatPagination(. Some(KeyArgs.toJs(. keyArgs))) let offsetLimitPagination: KeyArgs.t => FieldPolicy.Js_.t<'existing> = keyArgs => - Js_.offsetLimitPagination(. Some(keyArgs->KeyArgs.toJs)) + Js_.offsetLimitPagination(. Some(KeyArgs.toJs(. keyArgs))) let relayStylePagination: KeyArgs.t => FieldPolicy.Js_.t<'existing> = keyArgs => - Js_.relayStylePagination(. Some(keyArgs->KeyArgs.toJs)) + Js_.relayStylePagination(. Some(KeyArgs.toJs(. keyArgs))) diff --git a/src/ApolloClient__Types.res b/src/ApolloClient__Types.res index 6722809..7f8289e 100644 --- a/src/ApolloClient__Types.res +++ b/src/ApolloClient__Types.res @@ -41,4 +41,4 @@ type parseError = { type parseResult<'data> = result<'data, parseError> -type safeParse<'data, 'jsData> = 'jsData => parseResult<'data> +type safeParse<'data, 'jsData> = (. 'jsData) => parseResult<'data> diff --git a/src/ApolloClient__Utils.res b/src/ApolloClient__Utils.res index 56f620f..73e6722 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}) @@ -31,7 +31,7 @@ let safeParseAndLiftToCommonResultProps: ( | (None, None) => None } - switch jsData->Belt.Option.map(jsData => safeParse(jsData)) { + switch Belt.Option.mapU(jsData, (. jsData) => safeParse(jsData)) { | Some(Error(parseError)) => // Be careful we do not overwrite an existing error with a ParseError existingError->Belt.Option.isSome diff --git a/src/subscriptions-transport-ws/ApolloClient__SubscriptionsTransportWs.res b/src/subscriptions-transport-ws/ApolloClient__SubscriptionsTransportWs.res index 7629726..fe554e0 100644 --- a/src/subscriptions-transport-ws/ApolloClient__SubscriptionsTransportWs.res +++ b/src/subscriptions-transport-ws/ApolloClient__SubscriptionsTransportWs.res @@ -64,7 +64,7 @@ module ConnectionParamsOptions = { | Function(unit => ConnectionParams.t) | Promise(Js.Promise.t) - let toJs: t => Js_.t = x => + let toJs: (. t) => Js_.t = (. x) => switch x { | ConnectionParams(v) => Js_.Union.connectionParams(v) | Function(v) => Js_.Union.fn(v) @@ -106,8 +106,8 @@ module ClientOptions = { inactivityTimeout?: int, } - let toJs: t => Js_.t = t => { - connectionParams: ?t.connectionParams->Belt.Option.map(ConnectionParamsOptions.toJs), + let toJs: (. t) => Js_.t = (. t) => { + connectionParams: ?t.connectionParams->Belt.Option.mapU(ConnectionParamsOptions.toJs), timeout: ?t.timeout, reconnect: ?t.reconnect, reconnectionAttempts: ?t.reconnectionAttempts, @@ -194,7 +194,7 @@ module SubscriptionClient = { ) => t = (~url, ~options=?, ~webSocketImpl=?, ~webSocketProtocols=?, ()) => { let jsSubscriptionClient = Js_.make( ~url, - ~options=?options->Belt.Option.map(ClientOptions.toJs), + ~options=?options->Belt.Option.mapU(ClientOptions.toJs), ~webSocketImpl?, ~webSocketProtocols?, (), From b3c2f647dc8f4bad4a49c25d0e0625b598fd32b5 Mon Sep 17 00:00:00 2001 From: Rob Date: Wed, 9 Oct 2024 21:45:07 -0400 Subject: [PATCH 13/16] compiles on rescript 10 --- EXAMPLES/package.json | 4 ++-- package.json | 4 ++-- ...Client__Cache_InMemory_Policies_FieldPolicy.res | 2 +- .../core/ApolloClient__Core_ObservableQuery.res | 2 +- .../core/ApolloClient__Core_WatchQueryOptions.res | 2 +- .../retry/ApolloClient__Link_Retry_RetryLink.res | 4 ++-- .../react/types/ApolloClient__React_Types.res | 14 +++++++------- src/ApolloClient__Utils.res | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/EXAMPLES/package.json b/EXAMPLES/package.json index c12897f..7f0320d 100644 --- a/EXAMPLES/package.json +++ b/EXAMPLES/package.json @@ -10,10 +10,10 @@ "start": "rescript build -with-deps -w" }, "devDependencies": { - "@reasonml-community/graphql-ppx": "1.2.4-79d140a5.0", + "@reasonml-community/graphql-ppx": "1.2.4-1345e061.0", "graphql-client-example-server": "1.5.2", "html-webpack-plugin": "5.5.0", - "rescript": "11.1.4", + "rescript": "~10.1.2", "webpack": "5.75.0", "webpack-cli": "5.0.1", "webpack-dev-server": "^4.11.1" diff --git a/package.json b/package.json index c02ed8f..5c7dddc 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,9 @@ }, "devDependencies": { "@apollo/client": "^3.5.0", - "@reasonml-community/graphql-ppx": "1.2.4-79d140a5.0", + "@reasonml-community/graphql-ppx": "1.2.4-1345e061.0", "@rescript/react": "~0.11.0", - "rescript": "~11.1.4", + "rescript": "~10.1.2", "graphql": "^15.0.0", "jest": "26.5.3", "react": "^18.2.0", 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 c43c136..0cc75d7 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 @@ -132,7 +132,7 @@ module FieldMerge = { let toJs: (. t<'existing>) => Js_.t<'existing> = (. x) => switch x { | MergeFunction(mergeFunction) => - Js_.FieldMergeUnion.mergeFunction(. mergeFunction->FieldMergeFunction.toJs) + Js_.FieldMergeUnion.mergeFunction(. FieldMergeFunction.toJs(. mergeFunction)) | True => Js_.FieldMergeUnion.true_ } } diff --git a/src/@apollo/client/core/ApolloClient__Core_ObservableQuery.res b/src/@apollo/client/core/ApolloClient__Core_ObservableQuery.res index 5fd0041..b912664 100644 --- a/src/@apollo/client/core/ApolloClient__Core_ObservableQuery.res +++ b/src/@apollo/client/core/ApolloClient__Core_ObservableQuery.res @@ -115,7 +115,7 @@ module ObservableQuery = { ~safeParse, ) => { let parseWithOnErrorCall = (jsData, onError) => - switch safeParse(jsData) { + switch safeParse(. jsData) { | Ok(data) => Some(data) | Error({error}) => onError(error) diff --git a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res index 865b3da..ca8e66e 100644 --- a/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res +++ b/src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res @@ -200,7 +200,7 @@ module UpdateQueryFn = { ~subscriptionSafeParse, ) => (. jsQueryData, {subscriptionData: {data}}) => - switch (jsQueryData->querySafeParse, data->subscriptionSafeParse) { + switch (querySafeParse(. jsQueryData), subscriptionSafeParse(. data)) { | (Ok(queryData), Ok(subscriptionData)) => t( queryData, diff --git a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res index 99934a0..b52df73 100644 --- a/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res +++ b/src/@apollo/client/link/retry/ApolloClient__Link_Retry_RetryLink.res @@ -54,7 +54,7 @@ module Options = { | DelayFunctionOptions(delayFunctionOptions) => Js_.T_delayUnion.delayFunctionOptions(delayFunctionOptions) | DelayFunction(delayFunction) => - Js_.T_delayUnion.delayFunction(delayFunction->DelayFunction.toJs) + DelayFunction.toJs(.delayFunction)->Js_.T_delayUnion.delayFunction } ), attempts: ?t.attempts->Belt.Option.mapU((. attempts) => @@ -62,7 +62,7 @@ module Options = { | RetryFunctionOptions(retryFunctionOptions) => Js_.T_attemptsUnion.retryFunctionOptions(retryFunctionOptions->RetryFunctionOptions.toJs) | RetryFunction(retryFunction) => - Js_.T_attemptsUnion.retryFunction(retryFunction->RetryFunction.toJs) + RetryFunction.toJs(. retryFunction)->Js_.T_attemptsUnion.retryFunction } ), } diff --git a/src/@apollo/client/react/types/ApolloClient__React_Types.res b/src/@apollo/client/react/types/ApolloClient__React_Types.res index f89af63..bdb109d 100644 --- a/src/@apollo/client/react/types/ApolloClient__React_Types.res +++ b/src/@apollo/client/react/types/ApolloClient__React_Types.res @@ -79,7 +79,7 @@ module QueryHookOptions = { displayName: ?t.displayName, errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), onCompleted: ?t.onCompleted->Belt.Option.mapU((. onCompleted) => - (. jsData) => safeParse(jsData)->onCompleted + (. jsData) => safeParse(. jsData)->onCompleted ), onError: ?t.onError->Belt.Option.mapU((. onError) => (. jsApolloError) => ApolloError.fromJs(. jsApolloError)->onError @@ -155,7 +155,7 @@ module LazyQueryHookOptions = { displayName: ?t.displayName, errorPolicy: ?t.errorPolicy->Belt.Option.mapU(ErrorPolicy.toJs), onCompleted: ?t.onCompleted->Belt.Option.mapU((. onCompleted) => - (. jsData) => safeParse(jsData)->onCompleted + (. jsData) => safeParse(. jsData)->onCompleted ), onError: ?t.onError->Belt.Option.mapU((. onError) => (. jsApolloError) => ApolloError.fromJs(. jsApolloError)->onError @@ -373,7 +373,7 @@ module QueryResult = { jsFetchMoreOptions: Js_.t_fetchMoreOptions_updateQueryOptions<'jsData, 'jsVariables>, ) => switch ( - safeParse(previousResult), + safeParse(. previousResult), jsFetchMoreOptions.fetchMoreResult->Belt.Option.mapU(safeParse), ) { | (Ok(previousResult), Some(Ok(fetchMoreResult))) => @@ -486,7 +486,7 @@ module QueryResult = { let updateQuery = updateQueryFn => js->Js_.updateQuery((jsPreviousData, options) => - updateQueryFn(jsPreviousData->safeParse, options)->serialize + updateQueryFn(safeParse(. jsPreviousData), options)->serialize ) { @@ -793,14 +793,14 @@ module MutationHookOptions = { (. jsApolloError) => onError(ApolloError.fromJs(. jsApolloError)) ), onCompleted: ?t.onCompleted->Belt.Option.mapU((. onCompleted) => - (. jsData) => jsData->safeParse->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)), + update: ?t.update->Belt.Option.mapU((. updater) => MutationUpdaterFn.toJs(. updater, ~safeParse)), variables: ?t.variables->Belt.Option.mapU((. v) => v->serializeVariables->mapJsVariables), } } @@ -906,7 +906,7 @@ module MutationFunctionOptions = { ), 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), } diff --git a/src/ApolloClient__Utils.res b/src/ApolloClient__Utils.res index 73e6722..9a55892 100644 --- a/src/ApolloClient__Utils.res +++ b/src/ApolloClient__Utils.res @@ -31,7 +31,7 @@ let safeParseAndLiftToCommonResultProps: ( | (None, None) => None } - switch Belt.Option.mapU(jsData, (. jsData) => safeParse(jsData)) { + switch Belt.Option.mapU(jsData, safeParse) { | Some(Error(parseError)) => // Be careful we do not overwrite an existing error with a ParseError existingError->Belt.Option.isSome From 9a63ca380086c2f2c7a9d18e49c4d101f038440d Mon Sep 17 00:00:00 2001 From: Rob Date: Wed, 9 Oct 2024 21:51:52 -0400 Subject: [PATCH 14/16] compiles on rescript-11 uncurried: false --- EXAMPLES/bsconfig.json | 1 - EXAMPLES/package.json | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/EXAMPLES/bsconfig.json b/EXAMPLES/bsconfig.json index 000df21..b801d30 100644 --- a/EXAMPLES/bsconfig.json +++ b/EXAMPLES/bsconfig.json @@ -3,7 +3,6 @@ "uncurried": false, "graphql": { "apolloMode": true, - "uncurried": false, "extendMutation": "ApolloClient.GraphQL_PPX.ExtendMutation", "extendQuery": "ApolloClient.GraphQL_PPX.ExtendQuery", "extendSubscription": "ApolloClient.GraphQL_PPX.ExtendSubscription", diff --git a/EXAMPLES/package.json b/EXAMPLES/package.json index 7f0320d..9ec80d9 100644 --- a/EXAMPLES/package.json +++ b/EXAMPLES/package.json @@ -10,10 +10,10 @@ "start": "rescript build -with-deps -w" }, "devDependencies": { - "@reasonml-community/graphql-ppx": "1.2.4-1345e061.0", + "@reasonml-community/graphql-ppx": "1.2.4-79d140a5.0", "graphql-client-example-server": "1.5.2", "html-webpack-plugin": "5.5.0", - "rescript": "~10.1.2", + "rescript": "~11.1.4", "webpack": "5.75.0", "webpack-cli": "5.0.1", "webpack-dev-server": "^4.11.1" From 9f5098cbbf14dc3d8482ef797b96ebd97c87cd21 Mon Sep 17 00:00:00 2001 From: Rob Date: Fri, 11 Oct 2024 12:28:59 -0400 Subject: [PATCH 15/16] works on rescript-11 uncurried: true --- EXAMPLES/bsconfig.json | 5 +++-- EXAMPLES/package.json | 11 +++++------ EXAMPLES/src/Apollo.res | 2 +- EXAMPLES/src/WebpackEntry.res | 8 +++++++- EXAMPLES/src/clientUsage/ClientBasics.res | 2 +- EXAMPLES/src/docs/Docs.res | 3 ++- EXAMPLES/src/hooksUsage/Mutation.res | 1 + bsconfig.json | 2 +- package.json | 14 +++++++------- 9 files changed, 28 insertions(+), 20 deletions(-) diff --git a/EXAMPLES/bsconfig.json b/EXAMPLES/bsconfig.json index b801d30..49591c8 100644 --- a/EXAMPLES/bsconfig.json +++ b/EXAMPLES/bsconfig.json @@ -1,8 +1,9 @@ { "name": "examples", - "uncurried": false, + "uncurried": true, "graphql": { "apolloMode": true, + "uncurried": true, "extendMutation": "ApolloClient.GraphQL_PPX.ExtendMutation", "extendQuery": "ApolloClient.GraphQL_PPX.ExtendQuery", "extendSubscription": "ApolloClient.GraphQL_PPX.ExtendSubscription", @@ -16,7 +17,7 @@ "in-source": true } ], - "ppx-flags": ["@reasonml-community/graphql-ppx/ppx"], + "ppx-flags": ["@reasonml-community/graphql-ppx/_build/default/src/bin/bin.exe"], "jsx": { "version": 4, "mode": "automatic" diff --git a/EXAMPLES/package.json b/EXAMPLES/package.json index 9ec80d9..f36af7b 100644 --- a/EXAMPLES/package.json +++ b/EXAMPLES/package.json @@ -4,13 +4,13 @@ "description": "Examples for rescript-apollo-client", "private": true, "scripts": { + "build": "rescript build -with-deps", "clean": "rescript clean", "graphql-server": "graphql-client-example-server", "server": "webpack-dev-server", "start": "rescript build -with-deps -w" }, "devDependencies": { - "@reasonml-community/graphql-ppx": "1.2.4-79d140a5.0", "graphql-client-example-server": "1.5.2", "html-webpack-plugin": "5.5.0", "rescript": "~11.1.4", @@ -20,13 +20,12 @@ }, "dependencies": { "@apollo/client": "3.7.6", - "@rescript/react": "0.11.0", + "@rescript/react": "~0.11.0", "@ryyppy/rescript-promise": "2.1.0", "graphql": "^15.7.2", - "react": "18.2.0", - "react-dom": "18.2.0", - "reason-promise": "1.1.5", - "rescript-apollo-client": "3.2.0", + "react": "18.3.1", + "react-dom": "18.3.1", + "rescript-apollo-client": "*", "subscriptions-transport-ws": "0.11.0" } } diff --git a/EXAMPLES/src/Apollo.res b/EXAMPLES/src/Apollo.res index 09dd70d..dc9eaec 100644 --- a/EXAMPLES/src/Apollo.res +++ b/EXAMPLES/src/Apollo.res @@ -1,4 +1,4 @@ -let graphqlEndpoint = "localhost:4000" +let graphqlEndpoint = "localhost:4000/graphql" let headers = {"high": "five"} diff --git a/EXAMPLES/src/WebpackEntry.res b/EXAMPLES/src/WebpackEntry.res index dae9ef5..b87d9c0 100644 --- a/EXAMPLES/src/WebpackEntry.res +++ b/EXAMPLES/src/WebpackEntry.res @@ -1,4 +1,10 @@ switch ReactDOM.querySelector("#root") { -| Some(el) => ReactDOM.Client.createRoot(el)->ReactDOM.Client.Root.render() +| Some(el) => + ReactDOM.render( + + + , + el, + ) | None => () } diff --git a/EXAMPLES/src/clientUsage/ClientBasics.res b/EXAMPLES/src/clientUsage/ClientBasics.res index e1b0689..083b287 100644 --- a/EXAMPLES/src/clientUsage/ClientBasics.res +++ b/EXAMPLES/src/clientUsage/ClientBasics.res @@ -74,7 +74,7 @@ let statsSubscription = Apollo.client.subscribe( let make = () =>

- +

diff --git a/EXAMPLES/src/docs/Docs.res b/EXAMPLES/src/docs/Docs.res index 607a543..f1df585 100644 --- a/EXAMPLES/src/docs/Docs.res +++ b/EXAMPLES/src/docs/Docs.res @@ -138,6 +138,7 @@ module MutationTypical = { // combination of readQuery / writeQuery / writeFragment Js.log2("mutate.update To-Do: ", todo) let _unusedRef = writeFragment( + ~id="TodoItem:fragmentToDo", ~fragment=module(Fragments.TodoItem), ~data={ __typename: todo.__typename, @@ -145,7 +146,7 @@ module MutationTypical = { completed: None, text: "To-Do from writeFragment", }, - (), + () ) let _unusedRef = writeQuery( ~query=module(TodosQuery), diff --git a/EXAMPLES/src/hooksUsage/Mutation.res b/EXAMPLES/src/hooksUsage/Mutation.res index 92cf202..4c733c0 100644 --- a/EXAMPLES/src/hooksUsage/Mutation.res +++ b/EXAMPLES/src/hooksUsage/Mutation.res @@ -52,6 +52,7 @@ let make = () => { ") Js.log2("mutate.update To-Do: ", todo) let _unusedRef = writeFragment( + ~id="TodoItem:fragmentToDo", ~fragment=module(Fragments.TodoItem), ~data={ __typename: todo.__typename, diff --git a/bsconfig.json b/bsconfig.json index f28bec5..b791f2d 100644 --- a/bsconfig.json +++ b/bsconfig.json @@ -1,6 +1,6 @@ { "name": "rescript-apollo-client", - "uncurried": false, + "uncurried": true, "package-specs": [ { "module": "commonjs", diff --git a/package.json b/package.json index 5c7dddc..9e61d98 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "rescript-apollo-client", "description": "ReScript bindings for the Apollo Client ecosystem", - "version": "3.2.0", + "version": "3.3.0", "keywords": [ "Apollo", "BuckleScript", @@ -22,20 +22,20 @@ }, "devDependencies": { "@apollo/client": "^3.5.0", - "@reasonml-community/graphql-ppx": "1.2.4-1345e061.0", + "@reasonml-community/graphql-ppx": "1.2.4-79d140a5.0", "@rescript/react": "~0.11.0", - "rescript": "~10.1.2", "graphql": "^15.0.0", "jest": "26.5.3", - "react": "^18.2.0", - "react-dom": "^18.2.0", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "rescript": "~11.1.4", "subscriptions-transport-ws": "^0.9.17" }, "peerDependencies": { "@apollo/client": "^3.5.0", - "@reasonml-community/graphql-ppx": "^1.0.0", + "@reasonml-community/graphql-ppx": "*", "@rescript/react": "~0.10. || ~0.11.0", - "rescript": "^10.0.0" + "rescript": "^10.0.0 || ^11.0.0" }, "peerDependenciesMeta": { "rescript": { From 4500596942384ae2cd8f5d0cd072e0f64b71d8e5 Mon Sep 17 00:00:00 2001 From: Rob Date: Fri, 11 Oct 2024 12:30:15 -0400 Subject: [PATCH 16/16] works --- EXAMPLES/bsconfig.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EXAMPLES/bsconfig.json b/EXAMPLES/bsconfig.json index 49591c8..792ee07 100644 --- a/EXAMPLES/bsconfig.json +++ b/EXAMPLES/bsconfig.json @@ -1,9 +1,9 @@ { "name": "examples", - "uncurried": true, + "uncurried": false, "graphql": { "apolloMode": true, - "uncurried": true, + "uncurried": false, "extendMutation": "ApolloClient.GraphQL_PPX.ExtendMutation", "extendQuery": "ApolloClient.GraphQL_PPX.ExtendQuery", "extendSubscription": "ApolloClient.GraphQL_PPX.ExtendSubscription",