Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
21 changes: 6 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,20 @@
"test": "jest"
},
"devDependencies": {
"@apollo/client": "^3.5.0",
"@reasonml-community/graphql-ppx": "1.2.4-1345e061.0",
"@rescript/react": "~0.11.0",
"graphql": "^15.0.0",
"@apollo/client": "^3.10.8",
"@reasonml-community/graphql-ppx": "^1.2.4",
"@rescript/react": "~0.12.2",
"rescript": "^11.1.4",
"graphql": "^16.9.0",
"jest": "26.5.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rescript": "~10.1.2",
"subscriptions-transport-ws": "^0.9.17"
},
"peerDependencies": {
"@apollo/client": "^3.5.0",
"@reasonml-community/graphql-ppx": "^1.0.0",
"@rescript/react": "~0.10.0 || ~0.11.0 || ~0.12.0",
"rescript": "^10.0.0 || ^11.0.0"
},
"peerDependenciesMeta": {
"rescript": {
"optional": true
}
},
"workspaces": [
"EXAMPLES",
"./"
]
}
}
1 change: 0 additions & 1 deletion bsconfig.json → rescript.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "rescript-apollo-client",
"uncurried": false,
"package-specs": [
{
"module": "commonjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ module ApolloCache = {
(),
)
->Js.toOption
->Belt.Option.mapU(safeParse)
->Belt.Option.map(safeParse(_))
}

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

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

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

preserveJsPropsAndContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ module TypePolicy = {
fields?: t_fields,
}

let toJs: (. t) => Js_.t = (. t) => {
keyFields: ?t.keyFields->Belt.Option.mapU(KeyArgs.toJs),
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.mapU((. fields) =>
fields: ?t.fields->Belt.Option.mapU(fields =>
fields
->Belt.Array.mapU((. (fieldKey, t_field)) => (
->Belt.Array.mapU(((fieldKey, t_field)) => (
fieldKey,
switch t_field {
| ConcatPagination(keyArgs) =>
Expand All @@ -97,7 +97,7 @@ module TypePolicy = {

| FieldPolicy(fieldPolicy) => fieldPolicy->FieldPolicy.toJs->Js_.FieldsUnion.fieldPolicy
| FieldReadFunction(fieldReadFunction) =>
FieldReadFunction.toJs(. fieldReadFunction)->Js_.FieldsUnion.fieldReadFunction
FieldReadFunction.toJs(fieldReadFunction)->Js_.FieldsUnion.fieldReadFunction
},
))
->Js.Dict.fromArray
Expand Down Expand Up @@ -133,8 +133,10 @@ module TypePolicies = {

type t = array<(typename, TypePolicy.t)>

let toJs: (. t) => Js_.t = (. t) =>
t->Belt.Array.mapU((. (key, policy)) => (key, TypePolicy.toJs(. policy)))->Js.Dict.fromArray
let toJs: t => Js_.t = t =>
t
->Belt.Array.map(((key, policy)) => (key, TypePolicy.toJs(policy)))
->Js.Dict.fromArray
}

module PossibleTypesMap = {
Expand Down
8 changes: 4 additions & 4 deletions src/@apollo/client/core/ApolloClient__Core_ApolloClient.res
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ let make: (
(),
)
->Js.toOption
->Belt.Option.mapU(safeParse)
->Belt.Option.map(safeParse(_))
}

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

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

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

preserveJsPropsAndContext(
Expand Down
18 changes: 7 additions & 11 deletions src/@apollo/client/core/ApolloClient__Core_Types.res
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module MutationQueryReducer = {
queryVariables: Js.Json.t, // ACTUAL: Record<string, any>
}

type t<'jsData> = (. Js.Json.t, options<'jsData>) => Js.Json.t
type t<'jsData> = (Js.Json.t, options<'jsData>) => Js.Json.t
}

type options<'data> = {
Expand All @@ -148,11 +148,11 @@ module MutationQueryReducer = {
type t<'data> = (Js.Json.t, options<'data>) => Js.Json.t

let toJs: (
. t<'data>,
t<'data>,
~safeParse: Types.safeParse<'data, 'jsData>,
Js.Json.t,
Js_.options<'jsData>,
) => Js.Json.t = (. t, ~safeParse, previousResult, jsOptions) =>
) => Js.Json.t = (t, ~safeParse, previousResult, jsOptions) =>
t(
previousResult,
{
Expand All @@ -175,16 +175,12 @@ module MutationQueryReducersMap = {

type t<'data> = Js.Dict.t<MutationQueryReducer.t<'data>>

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) =>
(. json, options) =>
MutationQueryReducer.toJs(. mutationQueryReducer, ~safeParse, json, options),
t,
)
) => Js.Dict.map(mutationQueryReducer => {
(json, options) => MutationQueryReducer.toJs(mutationQueryReducer, ~safeParse, json, options)
}, t)
}

module Resolvers = {
Expand Down
73 changes: 33 additions & 40 deletions src/@apollo/client/core/ApolloClient__Core_WatchQueryOptions.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module ErrorPolicy = {
| Ignore
| All

let toJs = (. x) =>
let toJs = x =>
switch x {
| None => #none
| Ignore => #ignore
Expand All @@ -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"
Expand All @@ -54,7 +54,7 @@ module FetchPolicy__noCacheExtracted = {
}
type t = NoCache

let toJs = (. x) =>
let toJs = x =>
switch x {
| NoCache => "no-cache"
}
Expand All @@ -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"
Expand Down Expand Up @@ -172,7 +172,7 @@ module UpdateQueryFn = {
// variables?: TSubscriptionVariables;
// }) => TData;
type t<'jsQueryData, 'subscriptionVariables, 'jsSubscriptionData> = (
. 'jsQueryData,
'jsQueryData,
t_options<'jsSubscriptionData, 'subscriptionVariables>,
) => 'jsQueryData
}
Expand All @@ -198,23 +198,22 @@ module UpdateQueryFn = {
~querySafeParse,
~querySerialize,
~subscriptionSafeParse,
) =>
(. jsQueryData, {subscriptionData: {data}}) =>
switch (querySafeParse(. jsQueryData), subscriptionSafeParse(. data)) {
| (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 = {
Expand Down Expand Up @@ -260,7 +259,7 @@ module SubscribeToMoreOptions = {
) => {
document: t.document,
variables: t.variables,
updateQuery: ?t.updateQuery->Belt.Option.mapU((. onUpdateQueryFn) =>
updateQuery: ?t.updateQuery->Belt.Option.map(onUpdateQueryFn =>
UpdateQueryFn.toJs(
onUpdateQueryFn,
~onParseError=onUpdateQueryParseError,
Expand Down Expand Up @@ -316,17 +315,16 @@ module SubscriptionOptions = {

module MutationUpdaterFn = {
module Js_ = {
type t<'jsData> = (. ApolloCache.t<Js.Json.t>, FetchResult.Js_.t<'jsData>) => unit // Non-Js_ cache is correct here
type t<'jsData> = (ApolloCache.t<Js.Json.t>, FetchResult.Js_.t<'jsData>) => unit // Non-Js_ cache is correct here
}

type t<'data> = (ApolloCache.t<Js.Json.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, FetchResult.fromJs(jsFetchResult, ~safeParse))
) => (cache, jsFetchResult) =>
mutationUpdaterFn(cache, jsFetchResult->FetchResult.fromJs(~safeParse))
}

module RefetchQueryDescription = {
Expand All @@ -351,8 +349,8 @@ module RefetchQueryDescription = {

type t = array<t_variant>

let toJs: (. t) => Js_.t = (. arr) =>
Belt.Array.mapU(arr, (. x) =>
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)
Expand All @@ -376,7 +374,7 @@ module MutationOptions = {
// ...extends MutationBaseOption,
awaitRefetchQueries?: bool,
errorPolicy?: ErrorPolicy.Js_.t,
optimisticResponse?: (. 'jsVariables) => 'jsData,
optimisticResponse?: 'jsVariables => 'jsData,
update?: MutationUpdaterFn.Js_.t<'jsData>,
updateQueries?: MutationQueryReducersMap.Js_.t<'jsData>,
refetchQueries?: RefetchQueryDescription.Js_.t,
Expand Down Expand Up @@ -417,16 +415,11 @@ module MutationOptions = {
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.mapU((. optimisticResponse) =>
(. variables) => optimisticResponse(variables)->serialize
),
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)
),
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)),
variables: t.variables->serializeVariables->mapJsVariables,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ module RequestHandler = {
module Js_ = {
// export declare type RequestHandler = (operation: Operation, forward: NextLink) => Observable<FetchResult> | null;
type t = (
. Operation.Js_.t,
Operation.Js_.t,
NextLink.Js_.t,
) => Js.Null.t<Observable.t<FetchResult.Js_.t<Js.Json.t>, Js.Exn.t>>
}
Expand All @@ -180,5 +180,5 @@ module RequestHandler = {
NextLink.Js_.t,
) => option<Observable.t<FetchResult.Js_.t<Js.Json.t>, Js.Exn.t>>

let toJs: t => Js_.t = t => (. operation, forward) => t(operation, forward)->Js.Null.fromOption
let toJs: t => Js_.t = t => (operation, forward) => t(operation, forward)->Js.Null.fromOption
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module DelayFunction = {
// export interface DelayFunction {
// (count: number, operation: Operation, error: any): number;
// }
type t = (. int, Operation.Js_.t, option<Js.Json.t>) => int
type t = (int, Operation.Js_.t, option<Js.Json.t>) => int
}

type t = (~count: int, ~operation: Operation.t, ~error: option<Js.Json.t>) => int

let toJs: (. t) => Js_.t = (. t) =>
(. count, operation, error) => t(~count, ~operation=operation->Operation.fromJs, ~error)
let toJs: t => Js_.t = t => (count, operation, error) =>
t(~count, ~operation=operation->Operation.fromJs, ~error)
}

module DelayFunctionOptions = {
Expand Down
Loading