From 46c97e7d08e59d0ca720739da65bffecf15aed27 Mon Sep 17 00:00:00 2001 From: Dennis Falling Date: Mon, 18 Apr 2022 23:13:11 -0300 Subject: [PATCH 1/2] Implement FieldMerge and FieldMergeFunction --- ...t__Cache_InMemory_Policies_FieldPolicy.res | 65 ++++++++++++++++--- 1 file changed, 55 insertions(+), 10 deletions(-) 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 17b5c5b..552fcd2 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 @@ -4,13 +4,6 @@ module FieldNode = ApolloClient__Graphql.Language.Ast.FieldNode module ReadFieldFunction = ApolloClient__Cache_Core_Types_Common.ReadFieldFunction module ToReferenceFunction = ApolloClient__Cache_Core_Types_Common.ToReferenceFunction -module FieldMergeFunction = { - module Js_ = { - type t - } - type t = Js_.t -} - module StorageType = { type t = Js.Dict.t module Js_ = { @@ -90,6 +83,58 @@ module FieldFunctionOptions = { } } +module FieldMergeFunction = { + type t<'existing> = ('existing, 'existing, FieldFunctionOptions.t) => 'existing + + module Js_ = { + // export type FieldMergeFunction< + // TExisting = any, + // TIncoming = TExisting, + // // Passing the whole FieldFunctionOptions makes the current definition + // // independent from its implementation + // TOptions extends FieldFunctionOptions = FieldFunctionOptions + // > = ( + // existing: SafeReadonly | undefined, + // // The incoming parameter needs to be positional as well, for the same + // // reasons discussed in FieldReadFunction above. + // incoming: SafeReadonly, + // options: TOptions, + // ) => SafeReadonly; + 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) +} + +module FieldMerge = { + type t<'existing> = + | MergeFunction(FieldMergeFunction.t<'existing>) + | True + + module Js_ = { + // FieldMergeFunction | boolean; + module FieldMergeUnion: { + type t<'existing> + let mergeFunction: FieldMergeFunction.t<'existing> => t<'existing> + let true_: t<'existing> + } = { + @unboxed + type rec t<'existing> = Any('a): t<'existing> + let mergeFunction = (v: FieldMergeFunction.t<'existing>) => Any(v) + let true_ = Any(true) + } + + type t<'existing> = FieldMergeUnion.t<'existing> + } + + let toJs: t<'existing> => Js_.t<'existing> = x => + switch x { + | MergeFunction(mergeFunction) => mergeFunction->Js_.FieldMergeUnion.mergeFunction + | True => Js_.FieldMergeUnion.true_ + } +} + module FieldReadFunction = { type t<'existing> = (option<'existing>, FieldFunctionOptions.t) => 'existing @@ -166,7 +211,7 @@ module FieldPolicy = { type t<'existing> = { keyArgs: option, read: option>, - merge: option, + merge: option>, } module Js_ = { @@ -178,13 +223,13 @@ module FieldPolicy = { type t<'existing> = { keyArgs: option, read: option>, - merge: option, + merge: option>, } } 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, + merge: t.merge->Belt.Option.map(FieldMerge.toJs), } } From c176abdfba33fce5ffa1a11105f07d80a7a531da Mon Sep 17 00:00:00 2001 From: Dennis Falling Date: Tue, 19 Apr 2022 18:26:37 -0300 Subject: [PATCH 2/2] Fix incorrect usage of Js_ --- .../ApolloClient__Cache_InMemory_Policies_FieldPolicy.res | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 552fcd2..5fe0bde 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 @@ -116,12 +116,12 @@ module FieldMerge = { // FieldMergeFunction | boolean; module FieldMergeUnion: { type t<'existing> - let mergeFunction: FieldMergeFunction.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.t<'existing>) => Any(v) + let mergeFunction = (v: FieldMergeFunction.Js_.t<'existing>) => Any(v) let true_ = Any(true) } @@ -130,7 +130,8 @@ module FieldMerge = { let toJs: t<'existing> => Js_.t<'existing> = x => switch x { - | MergeFunction(mergeFunction) => mergeFunction->Js_.FieldMergeUnion.mergeFunction + | MergeFunction(mergeFunction) => + mergeFunction->FieldMergeFunction.toJs->Js_.FieldMergeUnion.mergeFunction | True => Js_.FieldMergeUnion.true_ } }