Skip to content

Commit

Permalink
Use RescriptCore.Dict types/mapValues instead of Js and autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
zatchheems committed Jan 6, 2025
1 parent fe398bc commit d7b27f0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module TypePolicy = {
queryType: option<bool>,
mutationType: option<bool>,
subscriptionType: option<bool>,
fields: option<Js.Dict.t<FieldsUnion.t>>,
fields: option<RescriptCore.Dict.t<FieldsUnion.t>>,
}
}

Expand All @@ -92,7 +92,7 @@ module TypePolicy = {
fields: option<t_fields>,
}

let toJs: (. t) => Js_.t = (. t) => {
let toJs: t => Js_.t = t => {
keyFields: t.keyFields->Belt.Option.map(KeyArgs.toJs),
queryType: t.queryType,
mutationType: t.mutationType,
Expand All @@ -114,7 +114,7 @@ module TypePolicy = {
fieldReadFunction->FieldReadFunction.toJs->Js_.FieldsUnion.fieldReadFunction
},
))
->Js.Dict.fromArray
->RescriptCore.Dict.fromArray
),
}

Expand All @@ -139,19 +139,21 @@ module TypePolicies = {
// export declare type TypePolicies = {
// [__typename: string]: TypePolicy;
// };
type t = Js.Dict.t<TypePolicy.Js_.t>
type t = RescriptCore.Dict.t<TypePolicy.Js_.t>
}

type typename = string

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
t
->Belt.Array.map(((key, policy)) => (key, TypePolicy.toJs(policy)))
->RescriptCore.Dict.fromArray
}

module PossibleTypesMap = {
type t = Js.Dict.t<array<string>>
type t = RescriptCore.Dict.t<array<string>>
module Js_ = {
// export declare type PossibleTypesMap = {
// [supertype: string]: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module ReadFieldFunction = ApolloClient__Cache_Core_Types_Common.ReadFieldFuncti
module ToReferenceFunction = ApolloClient__Cache_Core_Types_Common.ToReferenceFunction

module StorageType = {
type t = Js.Dict.t<Js.Json.t>
type t = RescriptCore.Dict.t<Js.Json.t>
module Js_ = {
type t = t
}
Expand All @@ -30,11 +30,11 @@ module FieldFunctionOptions = {
// mergeObjects<T extends StoreObject | Reference>(existing: T, incoming: T): T | undefined;
// }
type t = {
args: Js.nullable<Js.Dict.t<Js.Json.t>>,
args: Js.nullable<RescriptCore.Dict.t<Js.Json.t>>,
fieldName: string,
storeFieldName: string,
field: Js.nullable<FieldNode.t>,
variables: option<Js.Dict.t<Js.Json.t>>,
variables: option<RescriptCore.Dict.t<Js.Json.t>>,
isReference: bool,
toReference: unimplemented,
readField: unimplemented,
Expand All @@ -52,11 +52,11 @@ module FieldFunctionOptions = {
}

type t = {
args: Js.nullable<Js.Dict.t<Js.Json.t>>,
args: Js.nullable<RescriptCore.Dict.t<Js.Json.t>>,
fieldName: string,
storeFieldName: string,
field: Js.nullable<FieldNode.t>,
variables: option<Js.Dict.t<Js.Json.t>>,
variables: option<RescriptCore.Dict.t<Js.Json.t>>,
isReference: bool,
toReference: unimplemented,
storage: Js.nullable<StorageType.t>,
Expand Down
6 changes: 3 additions & 3 deletions src/@apollo/client/core/ApolloClient__Core_ApolloClient.res
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ module ApolloClientOptions = {
type t = {
uri: option<UriFunction.Js_.t>,
credentials: option<string>,
headers: option<Js.Dict.t<string>>,
headers: option<RescriptCore.Dict.t<string>>,
link: option<ApolloLink.Js_.t>,
cache: ApolloCache.t<Js.Json.t>, // Non-Js_ ApolloCache is correct here
ssrForceFetchDelay: option<int>,
Expand All @@ -220,7 +220,7 @@ module ApolloClientOptions = {
type t = {
uri: option<UriFunction.t>,
credentials: option<string>,
headers: option<Js.Dict.t<string>>,
headers: option<RescriptCore.Dict.t<string>>,
link: option<ApolloLink.t>,
cache: ApolloCache.t<Js.Json.t>,
ssrForceFetchDelay: option<int>,
Expand Down Expand Up @@ -574,7 +574,7 @@ let preserveJsPropsAndContext: (Js_.t, t) => t = %raw(`
let make: (
~uri: UriFunction.t=?,
~credentials: string=?,
~headers: Js.Dict.t<string>=?,
~headers: RescriptCore.Dict.t<string>=?,
~link: ApolloLink.t=?,
~cache: ApolloCache.t<Js.Json.t>,
~ssrForceFetchDelay: int=?,
Expand Down
13 changes: 5 additions & 8 deletions src/@apollo/client/core/ApolloClient__Core_Types.res
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,17 @@ module MutationQueryReducersMap = {
// }> = {
// [queryName: string]: MutationQueryReducer<T>;
// };
type t<'jsData> = Js.Dict.t<MutationQueryReducer.Js_.t<'jsData>>
type t<'jsData> = RescriptCore.Dict.t<MutationQueryReducer.Js_.t<'jsData>>
}

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

let toJs: (t<'data>, ~safeParse: Types.safeParse<'data, 'jsData>) => Js_.t<'jsData> = (
t,
~safeParse,
) =>
Js.Dict.map(
mutationQueryReducer => (json, options) =>
mutationQueryReducer->MutationQueryReducer.toJs(~safeParse, json, options),
t,
)
RescriptCore.Dict.mapValues(t, mutationQueryReducer => (json, options) =>
mutationQueryReducer->MutationQueryReducer.toJs(~safeParse, json, options))
}

module Resolvers = {
Expand All @@ -192,7 +189,7 @@ module Resolvers = {
// [field: string]: Resolver;
// };
// }
type t = Js.Dict.t<Js.Dict.t<Resolver.Js_.t>>
type t = RescriptCore.Dict.t<RescriptCore.Dict.t<Resolver.Js_.t>>
}
type t = Js_.t
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module FragmentDefinitionNode = ApolloClient__Graphql.Language.Ast.FragmentDefin

module FragmentMap = {
module Js_ = {
type t = Js.Dict.t<FragmentDefinitionNode.t>
type t = RescriptCore.Dict.t<FragmentDefinitionNode.t>
}

type t = Js_.t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ type t = {
source: option<Source.t>,
position: option<array<int>>,
originalError: Js.nullable<Js.Exn.t>,
extensions: option<Js.Dict.t<Js.Json.t>>,
extensions: option<RescriptCore.Dict.t<Js.Json.t>>,
}

0 comments on commit d7b27f0

Please sign in to comment.