forked from jeddeloh/rescript-apollo-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jeddeloh#150 from illusionalsagacity/rescript-10-1
Rescript 10.1
- Loading branch information
Showing
15 changed files
with
161 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
switch ReactDOM.querySelector("#root") { | ||
| Some(root) => ReactDOM.render(<App />, root) | ||
| Some(el) => ReactDOM.Client.createRoot(el)->ReactDOM.Client.Root.render(<App />) | ||
| None => () | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module ApolloError = ApolloClient.Types.ApolloError | ||
|
||
module DuplicateTodoMutation = %graphql(` | ||
mutation AddTodo($text: String!) { | ||
todo: addTodoSimple(text: $text) { | ||
id | ||
text | ||
} | ||
} | ||
`) | ||
|
||
module TodosQuery = %graphql(` | ||
query TodosQuery { | ||
todos: allTodos { | ||
id | ||
text | ||
completed | ||
} | ||
} | ||
`) | ||
|
||
let client = Apollo.client | ||
|
||
let func = async () => { | ||
let result = await client.query(~query=module(TodosQuery), ()) | ||
|
||
let firstTodo = switch result { | ||
| Ok({data: {todos}}) => | ||
switch todos->Belt.Array.get(0) { | ||
| Some(firstTodo) => Ok(firstTodo) | ||
| None => Error(ApolloError.make(~errorMessage="No To-Dos!", ())) | ||
} | ||
| Error(_) as error => error | ||
} | ||
|
||
let result = await ( | ||
switch firstTodo { | ||
| Ok(firstTodo) => | ||
client.mutate(~mutation=module(DuplicateTodoMutation), {text: firstTodo.text}) | ||
| Error(_) as error => Promise.resolve(error) | ||
} | ||
) | ||
|
||
switch result { | ||
| Ok(_) => Js.log("Duplicated first todo!") | ||
| Error(apolloError) => Js.log2("Something went wrong: ", apolloError.message) | ||
} | ||
} | ||
func()->ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.