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

Migrate to ReScript. #231

Merged
merged 3 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions examples/5-subscription/src/app/Util.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@bs.scope("Math") @bs.val external random: unit => float = "random"
@bs.scope("Math") @bs.val external floor: float => int = "floor"
@bs.send external toString: (int, int) => string = "toString"
@scope("Math") @val external random: unit => float = "random"
@scope("Math") @val external floor: float => int = "floor"
@send external toString: (int, int) => string = "toString"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more bs 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:rip: Can't say I'm sad to see it go!


let getRandomInt = (max: int) => floor(random() *. float_of_int(max))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open ReasonUrql

type subscriptionClientOptions = {
timeout: option<int>,
@bs.as("lazy")
@as("lazy")
lazy_: option<bool>,
reconnect: option<bool>,
reconnectionAttempts: option<int>,
Expand Down Expand Up @@ -35,13 +35,13 @@ let makeClientOptions = (
}

type t = {
@bs.meth
@meth
"request": Client.Exchanges.subscriptionOperation => Client.Exchanges.observableLike<
Types.executionResult,
>,
}

@bs.new @bs.module("subscriptions-transport-ws")
@new @module("subscriptions-transport-ws")
external subscriptionClient: (
~url: string,
~subscriptionClientConfig: subscriptionClientConfig=?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open ReasonUrql

type subscriptionClientOptions = {
timeout: option<int>,
@bs.as("lazy")
@as("lazy")
lazy_: option<bool>,
reconnect: option<bool>,
reconnectionAttempts: option<int>,
Expand All @@ -28,7 +28,7 @@ let makeClientOptions: (
) => subscriptionClientOptions

type t = {
@bs.meth
@meth
"request": Client.Exchanges.subscriptionOperation => Client.Exchanges.observableLike<
Types.executionResult,
>,
Expand Down
30 changes: 15 additions & 15 deletions src/Client.res
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ module Exchanges = {
. Wonka.Types.sourceT<Types.operation>,
) => Wonka.Types.sourceT<Types.operationResultJs<Js.Json.t>>

@bs.module("urql") external cacheExchange: t = "cacheExchange"
@bs.module("urql") external debugExchange: t = "debugExchange"
@bs.module("urql") external dedupExchange: t = "dedupExchange"
@bs.module("urql")
@module("urql") external cacheExchange: t = "cacheExchange"
@module("urql") external debugExchange: t = "debugExchange"
@module("urql") external dedupExchange: t = "dedupExchange"
@module("urql")
external fallbackExchangeIO: exchangeIO = "fallbackExchangeIO"
@bs.module("urql") external fetchExchange: t = "fetchExchange"
@bs.module("urql")
@module("urql") external fetchExchange: t = "fetchExchange"
@module("urql")
external composeExchanges: array<t> => t = "composeExchanges"
@bs.module("urql")
@module("urql")
external defaultExchanges: array<t> = "defaultExchanges"

/* Specific types for the subscriptionExchange. */
Expand Down Expand Up @@ -95,7 +95,7 @@ module Exchanges = {
enableAllOperations: option<bool>,
}

@bs.module("urql")
@module("urql")
external subscriptionExchangeJS: subscriptionExchangeOpts => t = "subscriptionExchange"

let subscriptionExchange = (~forwardSubscription, ~enableAllOperations=?, ()) =>
Expand All @@ -120,11 +120,11 @@ module Exchanges = {
initialState: option<Js.Dict.t<serializedResult>>,
}

@bs.send
@send
external restoreData: (~exchange: t, ~restore: Js.Json.t) => Js.Json.t = "restoreData"
@bs.send external extractData: (~exchange: t) => Js.Json.t = "extractData"
@send external extractData: (~exchange: t) => Js.Json.t = "extractData"

@bs.module("urql")
@module("urql")
external ssrExchange: (~ssrExchangeParams: ssrExchangeParams=?, unit) => t = "ssrExchange"
}

Expand All @@ -139,7 +139,7 @@ type clientOptions<'fetchOptions, 'fetchImpl> = {
maskTypename: bool,
}

@bs.new @bs.module("urql")
@new @module("urql")
external client: clientOptions<'fetchOptions, 'fetchImpl> => t = "Client"

/* `make` is equivalent to urql's `createClient`.
Expand Down Expand Up @@ -171,7 +171,7 @@ let make = (

/* Execution methods on the client. These allow you to imperatively execute GraphQL
operations outside of the provided hooks. */
@bs.send
@send
external executeQueryJs: (
~client: t,
~query: Types.graphqlRequest,
Expand Down Expand Up @@ -236,7 +236,7 @@ let executeQuery:
)
}

@bs.send
@send
external executeMutationJs: (
~client: t,
~mutation: Types.graphqlRequest,
Expand Down Expand Up @@ -300,7 +300,7 @@ let executeMutation:
)
}

@bs.send
@send
external executeSubscriptionJs: (
~client: t,
~subscription: Types.graphqlRequest,
Expand Down
20 changes: 10 additions & 10 deletions src/Client.resi
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ module Exchanges: {
. Wonka.Types.sourceT<Types.operation>,
) => Wonka.Types.sourceT<Types.operationResultJs<Js.Json.t>>

@bs.module("urql") external cacheExchange: t = "cacheExchange"
@bs.module("urql") external debugExchange: t = "debugExchange"
@bs.module("urql") external dedupExchange: t = "dedupExchange"
@bs.module("urql")
@module("urql") external cacheExchange: t = "cacheExchange"
@module("urql") external debugExchange: t = "debugExchange"
@module("urql") external dedupExchange: t = "dedupExchange"
@module("urql")
external fallbackExchangeIO: exchangeIO = "fallbackExchangeIO"
@bs.module("urql") external fetchExchange: t = "fetchExchange"
@bs.module("urql")
@module("urql") external fetchExchange: t = "fetchExchange"
@module("urql")
external composeExchanges: array<t> => t = "composeExchanges"
@bs.module("urql")
@module("urql")
external defaultExchanges: array<t> = "defaultExchanges"

/* Specific types for the subscriptionExchange. */
Expand Down Expand Up @@ -94,10 +94,10 @@ module Exchanges: {
initialState: option<Js.Dict.t<serializedResult>>,
}

@bs.send
@send
external restoreData: (~exchange: t, ~restore: Js.Json.t) => Js.Json.t = "restoreData"
@bs.send external extractData: (~exchange: t) => Js.Json.t = "extractData"
@bs.module("urql")
@send external extractData: (~exchange: t) => Js.Json.t = "extractData"
@module("urql")
external ssrExchange: (~ssrExchangeParams: ssrExchangeParams=?, unit) => t = "ssrExchange"
}

Expand Down
6 changes: 3 additions & 3 deletions src/Context.res
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@bs.module("urql") external context: React.Context.t<Client.t> = "Context"
@module("urql") external context: React.Context.t<Client.t> = "Context"

module Provider = {
@bs.module("urql") @react.component
@module("urql") @react.component
external make: (~value: Client.t, ~children: React.element) => React.element = "Provider"
}

module Consumer = {
@bs.module("urql") @react.component
@module("urql") @react.component
external make: (~children: Client.t => React.element) => React.element = "Consumer"
}
6 changes: 3 additions & 3 deletions src/Context.resi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@bs.module("urql") external context: React.Context.t<Client.t> = "Context"
@module("urql") external context: React.Context.t<Client.t> = "Context"

module Provider: {
@bs.module("urql") @react.component
@module("urql") @react.component
external make: (~value: Client.t, ~children: React.element) => React.element = "Provider"
}

module Consumer: {
@bs.module("urql") @react.component
@module("urql") @react.component
external make: (~children: Client.t => React.element) => React.element = "Consumer"
}
44 changes: 22 additions & 22 deletions src/Types.res
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
/* RequestPolicy to be used for queries. */
@bs.deriving(jsConverter)
@deriving(jsConverter)
type requestPolicy = [
| @bs.as("cache-first")
| @as("cache-first")
#CacheFirst
| @bs.as("cache-only")
| @as("cache-only")
#CacheOnly
| @bs.as("network-only")
| @as("network-only")
#NetworkOnly
| @bs.as("cache-and-network")
| @as("cache-and-network")
#CacheAndNetwork
]

/* OperationType for the active operation.
Use with operationTypeToJs for proper conversion to strings. */
@bs.deriving(jsConverter)
@deriving(jsConverter)
type operationType = [
| @bs.as("query")
| @as("query")
#Query
| @bs.as("mutation")
| @as("mutation")
#Mutation
| @bs.as("subscription")
| @as("subscription")
#Subscription
| @bs.as("teardown")
| @as("teardown")
#Teardown
]

/* Cache outcomes for operations. */
@bs.deriving(jsConverter)
type cacheOutcome = [@bs.as("miss") #Miss | @bs.as("partial") #Partial | @bs.as("hit") #Hit]
@deriving(jsConverter)
type cacheOutcome = [@as("miss") #Miss | @as("partial") #Partial | @as("hit") #Hit]

/* Debug information on operations. */
type operationDebugMeta = {
Expand All @@ -50,25 +50,25 @@ type operationContext = {
preferGetMethod: option<bool>,
}

@bs.deriving({abstract: light})
@deriving({abstract: light})
type partialOperationContext = {
@bs.optional
@optional
additionalTypenames: array<string>,
@bs.optional
@optional
fetch: (string, Fetch.requestInit) => Js.Promise.t<Fetch.response>,
@bs.optional
@optional
fetchOptions: Fetch.requestInit,
@bs.optional
@optional
requestPolicy: string,
@bs.optional
@optional
url: string,
@bs.optional
@optional
pollInterval: int,
@bs.optional
@optional
meta: operationDebugMeta,
@bs.optional
@optional
suspense: bool,
@bs.optional
@optional
preferGetMethod: bool,
}

Expand Down
22 changes: 11 additions & 11 deletions src/Types.resi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* RequestPolicy to be used for queries.
Use with requestPolicyToJs for proper conversion to string. */
@bs.deriving(jsConverter)
@deriving(jsConverter)
type requestPolicy = [#CacheFirst | #CacheOnly | #NetworkOnly | #CacheAndNetwork]

/* OperationType for the active operation.
Expand Down Expand Up @@ -31,25 +31,25 @@ type operationContext = {
preferGetMethod: option<bool>,
}

@bs.deriving({abstract: light})
@deriving({abstract: light})
type partialOperationContext = {
@bs.optional
@optional
additionalTypenames: array<string>,
@bs.optional
@optional
fetch: (string, Fetch.requestInit) => Js.Promise.t<Fetch.response>,
@bs.optional
@optional
fetchOptions: Fetch.requestInit,
@bs.optional
@optional
requestPolicy: string,
@bs.optional
@optional
url: string,
@bs.optional
@optional
pollInterval: int,
@bs.optional
@optional
meta: operationDebugMeta,
@bs.optional
@optional
suspense: bool,
@bs.optional
@optional
preferGetMethod: bool,
}

Expand Down
12 changes: 6 additions & 6 deletions src/Utils.res
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@bs.module("urql")
@module("urql")
external stringifyVariablies: 'a => string = "stringifyVariables"

@bs.module("urql")
@module("urql")
external createRequest: (~query: string, ~variables: Js.Json.t=?, unit) => Types.graphqlRequest =
"createRequest"

@bs.module("urql")
@module("urql")
external makeResult: (Types.operation, 'a, option<'b>) => Types.operationResultJs<'c> = "makeResult"

@bs.module("urql")
@module("urql")
external makeErrorResult: (Types.operation, Js.Exn.t, option<'a>) => Types.operationResultJs<'c> =
"makeErrorResult"

@bs.module("urql") external formatDocument: 'a => 'a = "formatDocument"
@module("urql") external formatDocument: 'a => 'a = "formatDocument"

@bs.module("urql") external maskTypename: 'a => 'a = "maskTypename"
@module("urql") external maskTypename: 'a => 'a = "maskTypename"
12 changes: 6 additions & 6 deletions src/Utils.resi
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@bs.module("urql")
@module("urql")
external stringifyVariablies: 'a => string = "stringifyVariables"

@bs.module("urql")
@module("urql")
external createRequest: (~query: string, ~variables: Js.Json.t=?, unit) => Types.graphqlRequest =
"createRequest"

@bs.module("urql")
@module("urql")
external makeResult: (Types.operation, 'a, option<'b>) => Types.operationResultJs<'c> = "makeResult"

@bs.module("urql")
@module("urql")
external makeErrorResult: (Types.operation, Js.Exn.t, option<'a>) => Types.operationResultJs<'c> =
"makeErrorResult"

@bs.module("urql") external formatDocument: 'a => 'a = "formatDocument"
@module("urql") external formatDocument: 'a => 'a = "formatDocument"

@bs.module("urql") external maskTypename: 'a => 'a = "maskTypename"
@module("urql") external maskTypename: 'a => 'a = "maskTypename"
2 changes: 1 addition & 1 deletion src/hooks/UseClient.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@bs.module("urql") external useClient: unit => Client.t = "useClient"
@module("urql") external useClient: unit => Client.t = "useClient"
2 changes: 1 addition & 1 deletion src/hooks/UseClient.resi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@bs.module("urql") external useClient: unit => Client.t = "useClient"
@module("urql") external useClient: unit => Client.t = "useClient"
2 changes: 1 addition & 1 deletion src/hooks/UseMutation.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type useMutationResponse<'variables, 'data> = (
executeMutation<'variables, 'data>,
)

@bs.module("urql")
@module("urql")
external useMutationJs: string => useMutationResponseJs<'dataJs> = "useMutation"

@ocaml.doc("
Expand Down
Loading