Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncurries internals for rescript 11 compatibility #160

Merged
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
2 changes: 2 additions & 0 deletions EXAMPLES/bsconfig.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions EXAMPLES/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,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"
Expand All @@ -26,7 +26,7 @@
"graphql": "^15.7.2",
"react": "18.3.1",
"react-dom": "18.3.1",
"rescript-apollo-client": "3.2.0",
"rescript-apollo-client": "*",
"subscriptions-transport-ws": "0.11.0"
}
}
17 changes: 17 additions & 0 deletions EXAMPLES/src/Apollo.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ let httpLink = ApolloClient.Link.HttpLink.make(
(),
)

let _retryLink = ApolloClient.Link.RetryLink.make(
~attempts=RetryFunction(async (~count, ~operation as _, ~error as _) => count < 3),
~delay=DelayFunction((~count as _, ~operation as _, ~error as _) => 1_000),
(),
)

let wsLink = {
open ApolloClient.Link.WebSocketLink
make(
Expand Down Expand Up @@ -42,3 +48,14 @@ let client = {
(),
)
}

client.onClearStore(~cb=async () => {
Js.log("store cleared")
})

client.onResetStore(~cb=async () => {
Js.log("store reset")
})

let _ = client.clearStore()
let _ = client.resetStore()
1 change: 1 addition & 0 deletions EXAMPLES/src/WebpackEntry.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@@warning("-3")
switch ReactDOM.querySelector("#root") {
| Some(el) =>
ReactDOM.render(
Expand Down
1 change: 1 addition & 0 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "rescript-apollo-client",
"uncurried": false,
"package-specs": [
{
"module": "commonjs",
Expand Down
16 changes: 8 additions & 8 deletions src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module ApolloCache = {
~fragmentName=?,
(),
) => {
let safeParse = Utils.safeParse(Fragment.parse)
let safeParse = Utils.safeParse(. Fragment.parse)

js
->Js_.readFragment(
Expand All @@ -196,7 +196,7 @@ module ApolloCache = {
(),
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let readQuery = (
Expand All @@ -212,7 +212,7 @@ module ApolloCache = {
~canonizeResults=?,
variables,
) => {
let safeParse = Utils.safeParse(Operation.parse)
let safeParse = Utils.safeParse(. Operation.parse)

js
->Js_.readQuery(
Expand All @@ -230,7 +230,7 @@ module ApolloCache = {
~optimistic,
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let writeFragment = (
Expand Down Expand Up @@ -304,7 +304,7 @@ module ApolloCache = {
~update,
variables,
) => {
let safeParse = Utils.safeParse(Operation.parse)
let safeParse = Utils.safeParse(. Operation.parse)

js
->Js_.updateQuery(
Expand All @@ -330,7 +330,7 @@ module ApolloCache = {
->Js.Nullable.fromOption,
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let updateFragment = (
Expand All @@ -345,7 +345,7 @@ module ApolloCache = {
~update,
(),
) => {
let safeParse = Utils.safeParse(Fragment.parse)
let safeParse = Utils.safeParse(. Fragment.parse)

js
->Js_.updateFragment(
Expand All @@ -367,7 +367,7 @@ module ApolloCache = {
->Js.Nullable.fromOption,
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

preserveJsPropsAndContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.map(KeyArgs.toJs),
let toJs: (. t) => Js_.t = (. t) => {
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) =>
Expand All @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ module FieldMergeFunction = {
// incoming: SafeReadonly<TIncoming>,
// options: TOptions,
// ) => SafeReadonly<TExisting>;
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 = {
Expand All @@ -116,22 +117,22 @@ module FieldMerge = {
// FieldMergeFunction<TExisting, TIncoming, TOptions> | 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(. FieldMergeFunction.toJs(. mergeFunction))
| True => Js_.FieldMergeUnion.true_
}
}
Expand All @@ -141,11 +142,12 @@ module FieldReadFunction = {

module Js_ = {
// export declare type FieldReadFunction<TExisting = any, TReadResult = TExisting> = (existing: SafeReadonly<TExisting> | 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 = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
}
Loading
Loading