@@ -22,28 +22,33 @@ module QueryHookOptions = {
2222 // export interface QueryHookOptions<TData = any, TVariables = OperationVariables> extends QueryFunctionOptions<TData, TVariables> {
2323 // query?: DocumentNode;
2424 // }
25- type t <'jsData , 'jsVariables > = {
26- query : option <Graphql .documentNode >,
25+ type t <'jsData , 'jsVariables >
26+
27+ // NOTE: We are using @obj here because passing properties that are defined with a value of undefined has effects
28+ @obj
29+ external make : (
30+ ~query : Graphql .documentNode = ?,
2731 // ...extends QueryFunctionOptions
28- displayName : option < string > ,
29- skip : option < bool > ,
30- onCompleted : option < 'jsData => unit > ,
31- onError : option < (. ApolloError .Js_ .t ) => unit > ,
32+ ~ displayName : string = ? ,
33+ ~ skip : bool = ? ,
34+ ~ onCompleted : 'jsData => unit = ? ,
35+ ~ onError : (. ApolloError .Js_ .t ) => unit = ? ,
3236 // ..extends BaseQueryOptions
33- client : option < ApolloClient .t > ,
34- context : option < Js .Json .t > , // ACTUAL: Record<string, any>
35- errorPolicy : option < string > ,
36- fetchPolicy : option < string > ,
37- nextFetchPolicy : option < string > ,
38- notifyOnNetworkStatusChange : option < bool > ,
39- partialRefetch : option < bool > ,
40- pollInterval : option < int > ,
37+ ~ client : ApolloClient .t = ? ,
38+ ~ context : Js .Json .t = ? , // ACTUAL: Record<string, any=? >
39+ ~ errorPolicy : string = ? ,
40+ ~ fetchPolicy : string = ? ,
41+ ~ nextFetchPolicy : string = ? ,
42+ ~ notifyOnNetworkStatusChange : bool = ? ,
43+ ~ partialRefetch : bool = ? ,
44+ ~ pollInterval : int = ? ,
4145 // INTENTIONALLY IGNORED (but now with safeParse and result unwrapping, maybe it shouldn't be?)
42- // returnPartialData: option( bool) ,
43- ssr : option < bool > ,
46+ // ~ returnPartialData: bool=? ,
47+ ~ ssr : bool = ? ,
4448 // We don't allow optional variables because it's not typesafe
45- variables : 'jsVariables ,
46- }
49+ ~variables : 'jsVariables ,
50+ unit ,
51+ ) => t <'jsData , 'jsVariables > = ""
4752 }
4853
4954 type t <'data , 'variables > = {
@@ -73,70 +78,62 @@ module QueryHookOptions = {
7378 ~mapJsVariables : 'jsVariables => 'jsVariables ,
7479 ~safeParse : Types .safeParse <'data , 'jsData >,
7580 ~serializeVariables : 'variables => 'jsVariables ,
76- ): Js_ .t <'jsData , 'jsVariables > => {
77- client : t .client ,
78- context : t .context ,
79- displayName : t .displayName ,
80- errorPolicy : t .errorPolicy -> Belt .Option .map (ErrorPolicy .toJs ),
81- onCompleted : t .onCompleted -> Belt .Option .map ((onCompleted , jsData ) =>
82- onCompleted (jsData -> safeParse )
83- ),
84- onError : t .onError -> Belt .Option .map ((onError , . jsApolloError ) =>
85- onError (ApolloError .fromJs (jsApolloError ))
86- ),
87- fetchPolicy : t .fetchPolicy -> Belt .Option .map (WatchQueryFetchPolicy .toJs ),
88- nextFetchPolicy : t .nextFetchPolicy -> Belt .Option .map (WatchQueryFetchPolicy .toJs ),
89- notifyOnNetworkStatusChange : t .notifyOnNetworkStatusChange ,
90- query : t .query ,
91- pollInterval : t .pollInterval ,
92- partialRefetch : t .partialRefetch ,
93- skip : t .skip ,
94- ssr : t .ssr ,
95- variables : t .variables -> serializeVariables -> mapJsVariables ,
96- }
81+ ): Js_ .t <'jsData , 'jsVariables > =>
82+ Js_ .make (
83+ ~client = ?t .client ,
84+ ~context = ?t .context ,
85+ ~displayName = ?t .displayName ,
86+ ~errorPolicy = ?t .errorPolicy -> Belt .Option .map (ErrorPolicy .toJs ),
87+ ~onCompleted = ?t .onCompleted -> Belt .Option .map ((onCompleted , jsData ) =>
88+ onCompleted (jsData -> safeParse )
89+ ),
90+ ~onError = ?t .onError -> Belt .Option .map ((onError , . jsApolloError ) =>
91+ onError (ApolloError .fromJs (jsApolloError ))
92+ ),
93+ ~fetchPolicy = ?t .fetchPolicy -> Belt .Option .map (WatchQueryFetchPolicy .toJs ),
94+ ~nextFetchPolicy = ?t .nextFetchPolicy -> Belt .Option .map (WatchQueryFetchPolicy .toJs ),
95+ ~notifyOnNetworkStatusChange = ?t .notifyOnNetworkStatusChange ,
96+ ~query = ?t .query ,
97+ ~pollInterval = ?t .pollInterval ,
98+ ~partialRefetch = ?t .partialRefetch ,
99+ ~skip = ?t .skip ,
100+ ~ssr = ?t .ssr ,
101+ ~variables = t .variables -> serializeVariables -> mapJsVariables ,
102+ (),
103+ )
97104}
98105
99106module LazyQueryHookOptions = {
100107 module Js_ = {
101108 // export interface LazyQueryHookOptions<TData = any, TVariables = OperationVariables> extends Omit<QueryFunctionOptions<TData, TVariables>, 'skip'> {
102109 // query?: DocumentNode;
103110 // }
104- @deriving (abstract )
105- type t <'jsData , 'jsVariables > = {
106- @optional
107- query : Graphql .documentNode ,
111+
112+ type t <'jsData , 'jsVariables >
113+
114+ // NOTE: We are using @obj here because passing properties that are defined with a value of undefined has effects
115+ @obj
116+ external make : (
117+ ~query : Graphql .documentNode = ?,
108118 // ...extends QueryFunctionOptions
109- @optional
110- displayName : string ,
111- @optional
112- onCompleted : 'jsData => unit ,
113- @optional
114- onError : (. ApolloError .Js_ .t ) => unit ,
119+ ~displayName : string = ?,
120+ ~onCompleted : 'jsData => unit = ?,
121+ ~onError : (. ApolloError .Js_ .t ) => unit = ?,
115122 // ..extends BaseQueryOptions
116- @optional
117- client : ApolloClient .t ,
118- @optional
119- context : Js .Json .t , // ACTUAL: Record<string, any>
120- @optional
121- errorPolicy : string ,
122- @optional
123- fetchPolicy : string ,
124- @optional
125- nextFetchPolicy : string ,
126- @optional
127- notifyOnNetworkStatusChange : bool ,
128- @optional
129- partialRefetch : bool ,
130- @optional
131- pollInterval : int ,
123+ ~client : ApolloClient .t = ?,
124+ ~context : Js .Json .t = ?, // ACTUAL: Record<string, any>,
125+ ~errorPolicy : string = ?,
126+ ~fetchPolicy : string = ?,
127+ ~nextFetchPolicy : string = ?,
128+ ~notifyOnNetworkStatusChange : bool = ?,
129+ ~partialRefetch : bool = ?,
130+ ~pollInterval : int = ?,
132131 // INTENTIONALLY IGNORED (but now with safeParse and result unwrapping, maybe it shouldn't be?)
133- // returnPartialData: option(bool),
134- @optional
135- ssr : bool ,
136- @optional
137- variables : 'jsVariables ,
138- }
139- let make = t
132+ // ~returnPartialData:bool=?,
133+ ~ssr : bool = ?,
134+ ~variables : 'jsVariables = ?,
135+ unit ,
136+ ) => t <'jsData , 'jsVariables > = ""
140137 }
141138
142139 type t <'data , 'variables > = {
@@ -730,44 +727,28 @@ module MutationHookOptions = {
730727 // export interface MutationHookOptions<TData = any, TVariables = OperationVariables> extends BaseMutationOptions<TData, TVariables> {
731728 // mutation?: DocumentNode;
732729 // }
733- @ocaml.doc ("
734- * We use deriving abstract here because option('jsVariables) is not typesafe,
735- * but still needs to be optional since a user has the option of providing
736- * the variables to the results of the hook rather than the hook itself
737- " )
738- @deriving (abstract )
739- type t <'jsData , 'jsVariables > = {
740- @optional
741- mutation : Graphql .documentNode ,
730+ type t <'jsData , 'jsVariables >
731+
732+ // NOTE: We are using @obj here because passing properties that are defined with a value of undefined has effects
733+ @obj
734+ external make : (
735+ ~mutation : Graphql .documentNode = ?,
742736 // ...extends BaseMutationOptions
743- @optional
744- awaitRefetchQueries : bool ,
745- @optional
746- client : ApolloClient .t , // Non-Js_ client is appropriate here
747- @optional
748- context : Js .Json .t , // actual: option(Context)
749- @optional
750- errorPolicy : ErrorPolicy .Js_ .t ,
751- @optional
752- fetchPolicy : FetchPolicy__noCacheExtracted .Js_ .t ,
753- @optional
754- ignoreResults : bool ,
755- @optional
756- notifyOnNetworkStatusChange : bool ,
757- @optional
758- onError : (. ApolloError .Js_ .t ) => unit ,
759- @optional
760- onCompleted : 'jsData => unit ,
761- @optional
762- optimisticResponse : 'jsVariables => 'jsData ,
763- @optional
764- refetchQueries : RefetchQueryDescription .Js_ .t ,
765- @optional
766- update : MutationUpdaterFn .Js_ .t <'jsData >,
767- @optional
768- variables : 'jsVariables ,
769- }
770- let make = t
737+ ~awaitRefetchQueries : bool = ?,
738+ ~client : ApolloClient .t = ?, // Non-Js_ client is appropriate here
739+ ~context : Js .Json .t = ?, // actual: option(Context)
740+ ~errorPolicy : ErrorPolicy .Js_ .t = ?,
741+ ~fetchPolicy : FetchPolicy__noCacheExtracted .Js_ .t = ?,
742+ ~ignoreResults : bool = ?,
743+ ~notifyOnNetworkStatusChange : bool = ?,
744+ ~onError : (. ApolloError .Js_ .t ) => unit = ?,
745+ ~onCompleted : 'jsData => unit = ?,
746+ ~optimisticResponse : 'jsVariables => 'jsData = ?,
747+ ~refetchQueries : RefetchQueryDescription .Js_ .t = ?,
748+ ~update : MutationUpdaterFn .Js_ .t <'jsData >= ?,
749+ ~variables : 'jsVariables = ?,
750+ unit ,
751+ ) => t <'jsData , 'jsVariables > = ""
771752 }
772753
773754 type t <'data , 'variables , 'jsVariables > = {
@@ -813,8 +794,8 @@ module MutationHookOptions = {
813794 onError (ApolloError .fromJs (jsApolloError ))
814795 ),
815796 ~onCompleted = ?t .onCompleted -> Belt .Option .map ((onCompleted , jsData ) =>
816- onCompleted (jsData -> safeParse )
817- ),
797+ onCompleted (jsData -> safeParse )
798+ ),
818799 ~optimisticResponse = ?t .optimisticResponse -> Belt .Option .map ((optimisticResponse , variables ) =>
819800 optimisticResponse (variables )-> serialize
820801 ),
@@ -881,10 +862,6 @@ module MutationFunctionOptions = {
881862 // context?: Context;
882863 // fetchPolicy?: WatchQueryFetchPolicy;
883864 // }
884- @ocaml.doc ("
885- * We use deriving abstract here because this is used in a context where passing in explicit
886- * properties could override one already passed in
887- " )
888865 type t <'jsData , 'jsVariables > = {
889866 // We don't allow optional variables because it's not typesafe
890867 variables : 'jsVariables ,
@@ -1203,18 +1180,23 @@ module SubscriptionHookOptions = {
12031180 // export interface SubscriptionHookOptions<TData = any, TVariables = OperationVariables> extends BaseSubscriptionOptions<TData, TVariables> {
12041181 // subscription?: DocumentNode;
12051182 // }
1206- type t <'jsData , 'jsVariables > = {
1207- subscription : option <Graphql .documentNode >,
1183+ type t <'jsData , 'jsVariables >
1184+
1185+ // NOTE: We are using @obj here because passing properties that are defined with a value of undefined has effects
1186+ @obj
1187+ external make : (
1188+ ~subscription : Graphql .documentNode = ?,
12081189 // ...extends BaseSubscriptionOptions
12091190 // Intentionally restricted to not be non-optional. `option(unit)` does not compile cleanly to `undefined`
1210- variables : 'jsVariables ,
1211- fetchPolicy : option <FetchPolicy .t >,
1212- shouldResubscribe : option <(. BaseSubscriptionOptions .Js_ .t <'jsData , 'jsVariables >) => bool >,
1213- client : option <ApolloClient .t >,
1214- skip : option <bool >,
1215- onSubscriptionData : option <(. OnSubscriptionDataOptions .Js_ .t <'jsData >) => unit >,
1216- onSubscriptionComplete : option <unit => unit >,
1217- }
1191+ ~variables : 'jsVariables ,
1192+ ~fetchPolicy : FetchPolicy .t = ?,
1193+ ~shouldResubscribe : (. BaseSubscriptionOptions .Js_ .t <'jsData , 'jsVariables >) => bool = ?,
1194+ ~client : ApolloClient .t = ?,
1195+ ~skip : bool = ?,
1196+ ~onSubscriptionData : (. OnSubscriptionDataOptions .Js_ .t <'jsData >) => unit = ?,
1197+ ~onSubscriptionComplete : unit => unit = ?,
1198+ unit ,
1199+ ) => t <'jsData , 'jsVariables > = ""
12181200 }
12191201
12201202 type t <'data , 'variables , 'jsVariables > = {
@@ -1233,22 +1215,26 @@ module SubscriptionHookOptions = {
12331215 ~mapJsVariables : 'jsVariables => 'jsVariables ,
12341216 ~safeParse : Types .safeParse <'data , 'jsData >,
12351217 ~serializeVariables : 'variables => 'jsVariables ,
1236- ) => Js_ .t <'jsData , 'jsVariables > = (t , ~mapJsVariables , ~safeParse , ~serializeVariables ) => {
1237- subscription : t .subscription ,
1238- variables : t .variables -> serializeVariables -> mapJsVariables ,
1239- fetchPolicy : t .fetchPolicy ,
1240- shouldResubscribe : t .shouldResubscribe -> Belt .Option .map ((
1241- shouldResubscribe ,
1242- . jsBaseSubscriptionOptions ,
1243- ) => shouldResubscribe (jsBaseSubscriptionOptions -> BaseSubscriptionOptions .fromJs )),
1244- client : t .client ,
1245- skip : t .skip ,
1246- onSubscriptionData : t .onSubscriptionData -> Belt .Option .map ((
1247- onSubscriptionData ,
1248- . jsOnSubscriptionDataOptions ,
1249- ) =>
1250- onSubscriptionData (jsOnSubscriptionDataOptions -> OnSubscriptionDataOptions .fromJs (~safeParse ))
1251- ),
1252- onSubscriptionComplete : t .onSubscriptionComplete ,
1253- }
1218+ ) => Js_ .t <'jsData , 'jsVariables > = (t , ~mapJsVariables , ~safeParse , ~serializeVariables ) =>
1219+ Js_ .make (
1220+ ~subscription = ?t .subscription ,
1221+ ~variables = t .variables -> serializeVariables -> mapJsVariables ,
1222+ ~fetchPolicy = ?t .fetchPolicy ,
1223+ ~shouldResubscribe = ?t .shouldResubscribe -> Belt .Option .map ((
1224+ shouldResubscribe ,
1225+ . jsBaseSubscriptionOptions ,
1226+ ) => shouldResubscribe (jsBaseSubscriptionOptions -> BaseSubscriptionOptions .fromJs )),
1227+ ~client = ?t .client ,
1228+ ~skip = ?t .skip ,
1229+ ~onSubscriptionData = ?t .onSubscriptionData -> Belt .Option .map ((
1230+ onSubscriptionData ,
1231+ . jsOnSubscriptionDataOptions ,
1232+ ) =>
1233+ onSubscriptionData (
1234+ jsOnSubscriptionDataOptions -> OnSubscriptionDataOptions .fromJs (~safeParse ),
1235+ )
1236+ ),
1237+ ~onSubscriptionComplete = ?t .onSubscriptionComplete ,
1238+ (),
1239+ )
12541240}
0 commit comments