Skip to content

Commit

Permalink
Update subscription examples
Browse files Browse the repository at this point in the history
  • Loading branch information
amiralies committed Nov 6, 2020
1 parent d2e6993 commit 3927176
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
11 changes: 8 additions & 3 deletions examples/5-subscription/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"reason": {
"react-jsx": 3
},
"bsc-flags": ["-bs-super-errors"],
"bsc-flags": [
"-bs-super-errors"
],
"sources": [
{
"dir": "src/app",
Expand All @@ -23,11 +25,14 @@
"wonka",
"reason-react",
"bs-css-emotion",
"bs-css"
"bs-css",
"@reasonml-community/graphql-ppx"
],
"refmt": 3,
"warnings": {
"error": "+5"
},
"ppx-flags": ["@baransu/graphql_ppx_re/ppx"]
"ppx-flags": [
"@reasonml-community/graphql-ppx/ppx"
]
}
4 changes: 2 additions & 2 deletions examples/5-subscription/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"dependencies": {
"bs-css-emotion": "^1.2.0",
"reason-react": "^0.7.0",
"reason-urql": "link:../../"
"reason-urql": "link:../../",
"@reasonml-community/graphql-ppx": "^1.0.1"
},
"devDependencies": {
"@baransu/graphql_ppx_re": "^0.7.1",
"apollo-server-express": "^2.14.2",
"bs-platform": "7.3.2",
"cors": "^2.8.5",
Expand Down
14 changes: 7 additions & 7 deletions examples/5-subscription/src/app/Circles.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open ReasonUrql;
module SubscribeRandomInt = [%graphql
{|
subscription subscribeNumbers {
newNumber @bsDecoder(fn: "string_of_int")
newNumber
}
|}
];
Expand Down Expand Up @@ -33,7 +33,7 @@ let getRandomHex = () => {
let make = () => {
let (Hooks.{response}, _) =
Hooks.useSubscription(
~request=SubscribeRandomInt.make(),
~query=(module SubscribeRandomInt),
~handler=Handler(handler),
(),
);
Expand All @@ -44,13 +44,13 @@ let make = () => {
| PartialData(d, _) =>
d
|> Array.to_list
|> List.mapi((index, datum) => {
let cx = datum##newNumber;
let cy = index === 0 ? datum##newNumber : d[index - 1]##newNumber;
|> List.mapi((index, datum: SubscribeRandomInt.t) => {
let cx = datum.newNumber;
let cy = index === 0 ? datum.newNumber : d[index - 1].newNumber;
<circle
key={string_of_int(index)}
cx
cy
cx={string_of_int(cx)}
cy={string_of_int(cy)}
stroke={getRandomHex()}
fill="none"
r={getRandomInt(30) |> string_of_int}
Expand Down
23 changes: 14 additions & 9 deletions examples/5-subscription/src/app/Squares.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open ReasonUrql;
module SubscribeRandomFloat = [%graphql
{|
subscription subscribeFloat {
newFloat @bsDecoder(fn: "Js.Float.toString")
newFloat
}
|}
];
Expand All @@ -29,23 +29,28 @@ let getRandomHex = () => {
{j|#$hex|j};
};

let request = SubscribeRandomFloat.make();

[@react.component]
let make = () => {
let (Hooks.{response}, _) =
Hooks.useSubscription(~request, ~handler=Handler(handler), ());
let ({Hooks.response}, _) =
Hooks.useSubscription(
~query=(module SubscribeRandomFloat),
~handler=Handler(handler),
(),
);

switch (response) {
| Fetching => <text> "Loading"->React.string </text>
| Data(d)
| PartialData(d, _) =>
Array.mapi(
(index, datum) =>
(index, datum: SubscribeRandomFloat.t) =>
<rect
key={datum##newFloat ++ string_of_int(index)}
x={datum##newFloat}
y={index === 0 ? datum##newFloat : d[index - 1]##newFloat}
key={datum.newFloat->Js.Float.toString ++ string_of_int(index)}
x={datum.newFloat->Js.Float.toString}
y={
(index === 0 ? datum.newFloat : d[index - 1].newFloat)
->Js.Float.toString
}
stroke={getRandomHex()}
fill="none"
height={getRandomInt(30) |> string_of_int}
Expand Down
17 changes: 7 additions & 10 deletions examples/5-subscription/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@
lodash "^4.17.11"
to-fast-properties "^2.0.0"

"@baransu/graphql_ppx_re@^0.7.1":
version "0.7.1"
resolved "https://registry.yarnpkg.com/@baransu/graphql_ppx_re/-/graphql_ppx_re-0.7.1.tgz#8146a36a94d56e65692d74488e2bd6cbd4eb8dc9"
integrity sha512-S9RYUWk8IkFxjE1Xl5eohRgbHJP5nCWOD6J1hMV3hY+D43igDrILq1doAXJatYB82BxcsrBC9V+VeU2LtCxIDw==

"@emotion/cache@^10.0.27":
version "10.0.29"
resolved "https://registry.yarnpkg.com/@emotion/cache/-/cache-10.0.29.tgz#87e7e64f412c060102d589fe7c6dc042e6f9d1e0"
Expand Down Expand Up @@ -170,6 +165,11 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@reasonml-community/graphql-ppx@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@reasonml-community/graphql-ppx/-/graphql-ppx-1.0.1.tgz#aabbaa2d32b290c1576c4d4c53e26ffce4bed98c"
integrity sha512-lYPM6J5lth3VWyzOdAIEerStK70xm0jObC86iyhrfl7lm7RFls0W+QyxbOhajpzl8MwFtNGq5gYZAi/E9GL7bw==

"@types/accepts@*", "@types/accepts@^1.3.5":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@types/accepts/-/accepts-1.3.5.tgz#c34bec115cfc746e04fe5a059df4ce7e7b391575"
Expand Down Expand Up @@ -4198,11 +4198,8 @@ reason-react@^0.7.0:
react-dom ">=16.8.1"

"reason-urql@link:../..":
version "2.1.0-rc.0"
dependencies:
bs-fetch "^0.6.2"
graphql "^15.3.0"
urql "1.10.0"
version "0.0.0"
uid ""

regenerator-runtime@^0.13.2:
version "0.13.2"
Expand Down

0 comments on commit 3927176

Please sign in to comment.