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

refactor: uncurries internal functions so that the package can compile on either curried/uncurried #3

Closed
wants to merge 16 commits into from
Closed
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 .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.re linguist-language=Reason
*.rei linguist-language=Reason
*.res linguist-language=ReScript
*.resi linguist-language=ReScript
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ yarn-error.log
.vscode/
lib/
node_modules/
.yarn/install-state.gz
8 changes: 3 additions & 5 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 All @@ -15,15 +17,11 @@
"in-source": true
}
],
"ppx-flags": ["@reasonml-community/graphql-ppx/ppx"],
"ppx-flags": ["@reasonml-community/graphql-ppx/_build/default/src/bin/bin.exe"],
"jsx": {
"version": 4,
"mode": "automatic"
},
"reason": {
"react-jsx": 3
},
"refmt": 3,
"sources": [
{
"dir": "src",
Expand Down
13 changes: 6 additions & 7 deletions EXAMPLES/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
"description": "Examples for rescript-apollo-client",
"private": true,
"scripts": {
"build": "rescript build -with-deps",
"clean": "rescript clean",
"graphql-server": "graphql-client-example-server",
"server": "webpack-dev-server",
"start": "rescript build -with-deps -w"
},
"devDependencies": {
"@reasonml-community/graphql-ppx": "1.2.3",
"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"
},
"dependencies": {
"@apollo/client": "3.7.6",
"@rescript/react": "0.11.0",
"@rescript/react": "~0.11.0",
"@ryyppy/rescript-promise": "2.1.0",
"graphql": "^15.7.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"reason-promise": "1.1.5",
"rescript-apollo-client": "3.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"rescript-apollo-client": "*",
"subscriptions-transport-ws": "0.11.0"
}
}
2 changes: 1 addition & 1 deletion EXAMPLES/src/Apollo.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let graphqlEndpoint = "localhost:4000"
let graphqlEndpoint = "localhost:4000/graphql"

let headers = {"high": "five"}

Expand Down
8 changes: 7 additions & 1 deletion EXAMPLES/src/WebpackEntry.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
switch ReactDOM.querySelector("#root") {
| Some(el) => ReactDOM.Client.createRoot(el)->ReactDOM.Client.Root.render(<App />)
| Some(el) =>
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
el,
)
| None => ()
}
2 changes: 1 addition & 1 deletion EXAMPLES/src/caching/LocalStateManagement.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let cache = {
"Query",
TypePolicy.make(
~fields=[
("someLocalStateField", FieldReadFunction((_existing, _options) => someLocalState())),
("someLocalStateField", FieldReadFunction((. _existing, _options) => someLocalState())),
],
(),
),
Expand Down
2 changes: 1 addition & 1 deletion EXAMPLES/src/clientUsage/ClientBasics.res
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let statsSubscription = Apollo.client.subscribe(
let make = () =>
<div>
<p>
<button onClick=logTodos> {"Log To-Dos (Reason Promise)"->React.string} </button>
<button onClick=logTodos> {"Log To-Dos"->React.string} </button>
</p>
<p>
<button onClick=addTodo> {"Add To-Do"->React.string} </button>
Expand Down
3 changes: 2 additions & 1 deletion EXAMPLES/src/docs/Docs.res
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ module MutationTypical = {
// combination of readQuery / writeQuery / writeFragment
Js.log2("mutate.update To-Do: ", todo)
let _unusedRef = writeFragment(
~id="TodoItem:fragmentToDo",
~fragment=module(Fragments.TodoItem),
~data={
__typename: todo.__typename,
id: "fragmentToDo",
completed: None,
text: "To-Do from writeFragment",
},
(),
()
)
let _unusedRef = writeQuery(
~query=module(TodosQuery),
Expand Down
1 change: 1 addition & 0 deletions EXAMPLES/src/hooksUsage/Mutation.res
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let make = () => {
")
Js.log2("mutate.update To-Do: ", todo)
let _unusedRef = writeFragment(
~id="TodoItem:fragmentToDo",
~fragment=module(Fragments.TodoItem),
~data={
__typename: todo.__typename,
Expand Down
5 changes: 1 addition & 4 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"name": "rescript-apollo-client",
"uncurried": true,
"package-specs": [
{
"module": "commonjs",
"in-source": true
}
],
"reason": {
"react-jsx": 3
},
"refmt": 3,
"jsx": {
"version": 4,
"mode": "automatic"
Expand Down
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rescript-apollo-client",
"description": "ReScript bindings for the Apollo Client ecosystem",
"version": "3.2.0",
"version": "3.3.0",
"keywords": [
"Apollo",
"BuckleScript",
Expand All @@ -16,33 +16,34 @@
"scripts": {
"build": "rescript build -with-deps",
"clean": "rescript clean",
"format:ci": "rescript format -check -all",
"start": "rescript build -with-deps -w",
"test": "jest"
},
"devDependencies": {
"@apollo/client": "^3.5.0",
"@reasonml-community/graphql-ppx": "^1.0.0",
"@reasonml-community/graphql-ppx": "1.2.4-79d140a5.0",
"@rescript/react": "~0.11.0",
"rescript": "~10.1.2",
"graphql": "^14.0.0",
"graphql": "^15.0.0",
"jest": "26.5.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rescript": "~11.1.4",
"subscriptions-transport-ws": "^0.9.17"
},
"peerDependencies": {
"@apollo/client": "^3.5.0",
"@reasonml-community/graphql-ppx": "^1.0.0",
"@reasonml-community/graphql-ppx": "*",
"@rescript/react": "~0.10. || ~0.11.0",
"bs-platform": "^8.2.0 || ^9.0.0",
"rescript": "^9.0.0 || ^10.0.0"
"rescript": "^10.0.0 || ^11.0.0"
},
"peerDependenciesMeta": {
"rescript": {
"optional": true
},
"bs-platform": {
"optional": true
}
}
},
"workspaces": [
"./",
"./EXAMPLES"
]
}
61 changes: 30 additions & 31 deletions src/@apollo/client/cache/core/ApolloClient__Cache_Core_Cache.res
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,21 @@ module ApolloCache = {
~fragmentName=?,
(),
) => {
let safeParse = Utils.safeParse(Fragment.parse)

let safeParse = Utils.safeParse(. Fragment.parse)
js
->Js_.readFragment(
~options={
id: id,
fragment: Fragment.query,
fragmentName: fragmentName,
optimistic: optimistic,
canonizeResults: canonizeResults,
fragmentName: ?fragmentName,
optimistic: ?optimistic,
canonizeResults: ?canonizeResults,
},
~optimistic?,
(),
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

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

js
->Js_.readQuery(
~options=DataProxy.ReadQueryOptions.toJs(
{
id: id,
id: ?id,
query: Operation.query,
variables: variables,
optimistic: optimistic,
canonizeResults: canonizeResults,
optimistic: ?optimistic,
canonizeResults: ?canonizeResults,
},
~mapJsVariables,
~serializeVariables=Operation.serializeVariables,
),
~optimistic,
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

let writeFragment = (
Expand All @@ -247,12 +246,12 @@ module ApolloCache = {
js->Js_.writeFragment(
~options=DataProxy.WriteFragmentOptions.toJs(
{
broadcast: broadcast,
broadcast: ?broadcast,
data: data,
id: id,
fragment: Fragment.query,
fragmentName: fragmentName,
overwrite: overwrite,
fragmentName: ?fragmentName,
overwrite: ?overwrite,
},
~serialize=Fragment.serialize,
),
Expand All @@ -275,12 +274,12 @@ module ApolloCache = {
js->Js_.writeQuery(
~options=DataProxy.WriteQueryOptions.toJs(
{
broadcast: broadcast,
broadcast: ?broadcast,
data: data,
id: id,
id: ?id,
query: Operation.query,
variables: variables,
overwrite: overwrite,
overwrite: ?overwrite,
},
~mapJsVariables,
~serialize=Operation.serialize,
Expand All @@ -304,18 +303,18 @@ module ApolloCache = {
~update,
variables,
) => {
let safeParse = Utils.safeParse(Operation.parse)
let safeParse = Utils.safeParse(. Operation.parse)

js
->Js_.updateQuery(~options=DataProxy.UpdateQueryOptions.toJs(
{
optimistic: optimistic,
canonizeResults: canonizeResults,
broadcast: broadcast,
id: id,
optimistic: ?optimistic,
canonizeResults: ?canonizeResults,
broadcast: ?broadcast,
id: ?id,
query: Operation.query,
variables: variables,
overwrite: overwrite,
overwrite: ?overwrite,
},
~mapJsVariables,
~serializeVariables=Operation.serializeVariables,
Expand All @@ -328,7 +327,7 @@ module ApolloCache = {
->Js.Nullable.fromOption
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

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

js
->Js_.updateFragment(~options=DataProxy.UpdateFragmentOptions.toJs({
optimistic: optimistic,
canonizeResults: canonizeResults,
broadcast: broadcast,
optimistic: ?optimistic,
canonizeResults: ?canonizeResults,
broadcast: ?broadcast,
id: id,
fragment: Fragment.query,
fragmentName: fragmentName,
overwrite: overwrite,
fragmentName: ?fragmentName,
overwrite: ?overwrite,
}), ~update=jsData =>
jsData
->Js.nullToOption
Expand All @@ -363,7 +362,7 @@ module ApolloCache = {
->Js.Nullable.fromOption
)
->Js.toOption
->Belt.Option.map(safeParse)
->Belt.Option.mapU(safeParse)
}

preserveJsPropsAndContext(
Expand Down
Loading
Loading