rescript-relay 0.0.0-autocodesplit-09ee6f6c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +942 -0
- package/README.md +111 -0
- package/cli/cli.js +472 -0
- package/compiler.js +11 -0
- package/package.json +65 -0
- package/postinstall.js +189 -0
- package/ppx-linux +0 -0
- package/ppx-macos-arm64 +0 -0
- package/ppx-macos-latest +0 -0
- package/ppx-windows-latest +0 -0
- package/relay-compiler-linux-musl/relay +0 -0
- package/relay-compiler-linux-x64/relay +0 -0
- package/relay-compiler-macos-arm64/relay +0 -0
- package/relay-compiler-macos-x64/relay +0 -0
- package/relay-compiler-win-x64/relay.exe +0 -0
- package/rescript.json +19 -0
- package/src/ReactDOMExperimental.bs.js +23 -0
- package/src/ReactDOMExperimental.res +16 -0
- package/src/ReactExperimental.bs.js +23 -0
- package/src/ReactExperimental.res +21 -0
- package/src/ReactExperimental.resi +18 -0
- package/src/RescriptRelay.bs.js +329 -0
- package/src/RescriptRelay.res +858 -0
- package/src/RescriptRelay.resi +897 -0
- package/src/RescriptRelayUtils.bs.js +76 -0
- package/src/RescriptRelayUtils.res +89 -0
- package/src/RescriptRelayUtils.resi +36 -0
- package/src/RescriptRelay_Fragment.bs.js +122 -0
- package/src/RescriptRelay_Fragment.res +243 -0
- package/src/RescriptRelay_Fragment.resi +85 -0
- package/src/RescriptRelay_Internal.bs.js +102 -0
- package/src/RescriptRelay_Internal.res +71 -0
- package/src/RescriptRelay_Internal.resi +20 -0
- package/src/RescriptRelay_Mutation.bs.js +57 -0
- package/src/RescriptRelay_Mutation.res +144 -0
- package/src/RescriptRelay_Mutation.resi +52 -0
- package/src/RescriptRelay_Query.bs.js +101 -0
- package/src/RescriptRelay_Query.res +177 -0
- package/src/RescriptRelay_Query.resi +62 -0
- package/src/RescriptRelay_RelayResolvers.bs.js +13 -0
- package/src/RescriptRelay_RelayResolvers.res +21 -0
- package/src/RescriptRelay_RelayResolvers.resi +10 -0
- package/src/RescriptRelay_Subscriptions.bs.js +24 -0
- package/src/RescriptRelay_Subscriptions.res +50 -0
- package/src/RescriptRelay_Subscriptions.resi +14 -0
- package/src/utils.js +418 -0
- package/src/utils.mjs +418 -0
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# rescript-relay
|
|
2
|
+
|
|
3
|
+
Use Relay with ReScript.
|
|
4
|
+
|
|
5
|
+
[**Join our Discord**](https://discord.gg/wzj4EN8XDc)
|
|
6
|
+
|
|
7
|
+
## Getting started
|
|
8
|
+
|
|
9
|
+
> Are you using version `>= 0.13.0` and ReScript syntax with VSCode? Make sure you install our [dedicated VSCode extension](https://marketplace.visualstudio.com/items?itemName=GabrielNordeborn.vscode-rescript-relay). Note: It only works with ReScript syntax.
|
|
10
|
+
|
|
11
|
+
Check out the [documentation](https://rescript-relay-documentation.vercel.app).
|
|
12
|
+
|
|
13
|
+
Also, check out the [changelog](CHANGELOG.md) - things will continue to change between versions (including breaking changes, although we'll try and keep them to a minimum) as we iterate and reach a stable version.
|
|
14
|
+
|
|
15
|
+
## What it looks like
|
|
16
|
+
|
|
17
|
+
Your components define what data they need through `%relay()`.
|
|
18
|
+
|
|
19
|
+
```rescript
|
|
20
|
+
/* Avatar.res */
|
|
21
|
+
module UserFragment = %relay(`
|
|
22
|
+
fragment Avatar_user on User {
|
|
23
|
+
firstName
|
|
24
|
+
lastName
|
|
25
|
+
avatarUrl
|
|
26
|
+
}
|
|
27
|
+
`)
|
|
28
|
+
|
|
29
|
+
@react.component
|
|
30
|
+
let make = (~user) => {
|
|
31
|
+
let userData = UserFragment.use(user)
|
|
32
|
+
|
|
33
|
+
<img
|
|
34
|
+
className="avatar"
|
|
35
|
+
src=userData.avatarUrl
|
|
36
|
+
alt={
|
|
37
|
+
userData.firstName ++ " "
|
|
38
|
+
userData.lastName
|
|
39
|
+
}
|
|
40
|
+
/>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Fragments can include other fragments. This allows you to break your UI into encapsulated components defining their own data demands.
|
|
46
|
+
|
|
47
|
+
Hooks to use your fragments are autogenerated for you. The hook needs a _fragment reference_ from the GraphQL object where it was spread. Any object with one or more fragments spread on it will have a `fragmentRefs` prop on it, `someObj.fragmentRefs`. Pass that to the fragment hook.
|
|
48
|
+
|
|
49
|
+
`Avatar_user` is spread right on the fragment, so we pass `userData.fragmentRefs` to the `<Avatar />` component since we know it'll contain the fragment ref for `Avatar_user` that `<Avatar />` needs. The `<Avatar />` component then uses that to get its data.
|
|
50
|
+
|
|
51
|
+
```rescript
|
|
52
|
+
/* UserProfile.res */
|
|
53
|
+
module UserFragment = %relay(`
|
|
54
|
+
fragment UserProfile_user on User {
|
|
55
|
+
firstName
|
|
56
|
+
lastName
|
|
57
|
+
friendCount
|
|
58
|
+
...Avatar_user
|
|
59
|
+
}
|
|
60
|
+
`)
|
|
61
|
+
|
|
62
|
+
@react.component
|
|
63
|
+
let make = (~user) => {
|
|
64
|
+
let userData = UserFragment.use(user)
|
|
65
|
+
|
|
66
|
+
<div>
|
|
67
|
+
<Avatar user=userData.fragmentRefs />
|
|
68
|
+
<h1> {React.string(userData.firstName ++ (" " ++ userData.lastName))} </h1>
|
|
69
|
+
<div>
|
|
70
|
+
<p>
|
|
71
|
+
{React.string(
|
|
72
|
+
userData.firstName ++ (" has " ++ (userData.friendCount->string_of_int ++ " friends.")),
|
|
73
|
+
)}
|
|
74
|
+
</p>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Finally, you make a query using `%relay()` and include the fragments needed to render the entire tree of components.
|
|
81
|
+
|
|
82
|
+
```rescript
|
|
83
|
+
/* Dashboard.res */
|
|
84
|
+
module Query = %relay(`
|
|
85
|
+
query DashboardQuery {
|
|
86
|
+
me {
|
|
87
|
+
...UserProfile_user
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`)
|
|
91
|
+
|
|
92
|
+
@react.component
|
|
93
|
+
let make = () => {
|
|
94
|
+
let queryData = Query.use(~variables=(), ())
|
|
95
|
+
|
|
96
|
+
<div> <UserProfile user=queryData.me.fragmentRefs /> </div>
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Note about versioning
|
|
102
|
+
|
|
103
|
+
There's plenty of work ongoing to bring RescriptRelay to full ReScript v11 support, including uncurried mode. Here's the versioning scheme that'll be followed going forward:
|
|
104
|
+
|
|
105
|
+
- 1.x will receive critical bug fixes etc, but new features won't be added
|
|
106
|
+
- 2.x will soon ship, and it'll focus on compatibility with ReScript v11, and uncurried mode (uncurried mode will be optional). This is intended to make the transition to v11+ smooth
|
|
107
|
+
- 3.x will also soon ship, and that'll fully embrace uncurried mode (no curried mode available), and add a bunch of new stuff + change existing APIs to make them better and more ergonomic
|
|
108
|
+
|
|
109
|
+
## Examples
|
|
110
|
+
|
|
111
|
+
- A general example showcasing most available features: https://github.com/zth/rescript-relay/tree/master/example
|