Skip to content

Commit ffee58a

Browse files
committed
operation.text + operation.id is nullable
1 parent 3df77fa commit ffee58a

File tree

9 files changed

+33
-17
lines changed

9 files changed

+33
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Add support for top level `@catch` on fragments on unions.
44
- Add parameter `excludedIds: array<dataId>` to `invalidateRecordsByIds` to allow excluding a list of connection IDs from invalidation.
5+
- **BREAKING:** `operation.text` and `operation.id` are now nullable, which better reflects what values they can actually have in runtime.
56

67
# 3.2.0
78

example/src/RelayEnv.res

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ let fetchQuery: RescriptRelay.Network.fetchFunctionPromise = async (
2222
"http://localhost:4000/graphql",
2323
{
2424
method: #POST,
25-
body: {"query": operation.text, "variables": variables}
25+
body: {
26+
"query": operation.text->Js.Nullable.toOption->Belt.Option.getWithDefault(""),
27+
"variables": variables,
28+
}
2629
->Js.Json.stringifyAny
2730
->Belt.Option.getExn
2831
->Body.string,
@@ -64,15 +67,15 @@ let subscriptionFunction: RescriptRelay.Network.subscribeFn = (
6467
) => {
6568
let subscriptionQuery: GraphQLWs.Client.subscribeOptions = {
6669
operationName: operation.name,
67-
query: operation.text,
68-
variables: variables,
70+
query: operation.text->Js.Nullable.toOption->Belt.Option.getWithDefault(""),
71+
variables,
6972
}
7073

7174
RescriptRelay.Observable.make(sink => {
7275
let unsubscribe = GraphQLWs.Client.subscribe(wsClient, subscriptionQuery, sink)
7376

7477
Some({
75-
unsubscribe: unsubscribe,
78+
unsubscribe,
7679
closed: false,
7780
})
7881
})

packages/rescript-relay/src/RescriptRelay.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ module Network = {
534534
type operationMetadata = {codesplits?: array<codesplitsMetadata>}
535535

536536
type operation = {
537-
id: string,
538-
text: string,
537+
id: Js.Nullable.t<string>,
538+
text: Js.Nullable.t<string>,
539539
name: string,
540540
operationKind: string,
541541
metadata: Js.Nullable.t<operationMetadata>,

packages/rescript-relay/src/RescriptRelay.resi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,10 +1017,15 @@ module Network: {
10171017
- `metadata`: Optional operation metadata
10181018
*/
10191019
type operation = {
1020-
id: string,
1021-
text: string,
1020+
/** The operation ID. Set if persisted queries are enabled, otherwise not set. */
1021+
id: Js.Nullable.t<string>,
1022+
/** The operation text. Not set for persisted queries, or if this is a client-only query that will not make a network request. */
1023+
text: Js.Nullable.t<string>,
1024+
/** The operation name. */
10221025
name: string,
1026+
/** The operation kind. */
10231027
operationKind: string,
1028+
/** Optional operation metadata. */
10241029
metadata: Js.Nullable.t<operationMetadata>,
10251030
}
10261031

rescript-relay-documentation/docs/api-reference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,14 @@ Represents the network layer.
920920

921921
```rescript
922922
type operation = {
923-
id: string,
924-
text: string,
923+
id: Nullable.t<string>,
924+
text: Nullable.t<string>,
925925
name: string,
926926
operationKind: string,
927927
}
928928
```
929929

930-
The operation fed to the `NetworkLayer` when Relay wants to make a request. Please note that if you're using persisted queries, `id` will exist but `text` won't, and vice versa when not using persisted queries.
930+
The operation fed to the `NetworkLayer` when Relay wants to make a request. Please note that if you're using persisted queries, `id` will exist but `text` will be null, and vice versa when not using persisted queries.
931931

932932
### [Network.subscribeFn](#networksubscribefn)
933933

rescript-relay-documentation/docs/codesplit-directive.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ let fetchQuery: RescriptRelay.Network.fetchFunctionPromise = async (
6060
"https://your.server/graphql",
6161
{
6262
method: #POST,
63-
body: {"query": operation.text, "id": operation.id, "variables": variables}
64-
->Js.Json.stringifyAny
65-
->Belt.Option.getExn
63+
body: {
64+
"query": operation.text->Nullable.getOr(""),
65+
"id": operation.id->Nullable.getOr(""),
66+
"variables": variables
67+
}
68+
->JSON.stringifyAny
69+
->Option.getExn
6670
->Body.string,
6771
headers: Headers.fromObject({
6872
"content-type": "application/json",

rescript-relay-documentation/docs/getting-started.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ let fetchQuery: RescriptRelay.Network.fetchFunctionPromise = async (
140140
"http://localhost:4000/graphql",
141141
{
142142
method: #POST,
143-
body: {"query": operation.text, "variables": variables}
143+
body: {
144+
"query": operation.text->Nullable.getOr(""),
145+
"variables": variables
146+
}
144147
->JSON.stringifyAny
145148
->Option.getExn
146149
->Body.string,

rescript-relay-documentation/docs/subscriptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let subscriptionClient = SubscriptionsTransportWs.createSubscriptionClient(
4343
)
4444
4545
let subscriptionFunction: RescriptRelay.Network.subscribeFn = (config, variables, _cacheConfig) => {
46-
let query = config.text
46+
let query = config.text->Nullable.getOr("")
4747
let subscriptionQuery: SubscriptionsTransportWs.operationOptions = {
4848
query: query,
4949
variables: variables,

rescript-relay-documentation/docs/using-with-hasura.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let fetchQuery: RescriptRelay.Network.fetchFunctionPromise = (operation, variabl
3838
RequestInit.make(
3939
~method_=Post,
4040
~body=Js.Dict.fromList(list{
41-
("query", Js.Json.string(operation.text)),
41+
("query", Js.Json.string(operation.text->Js.Nullable.toOption->Belt.Option.getWithDefault(""))),
4242
("variables", variables),
4343
})
4444
|> Js.Json.object_

0 commit comments

Comments
 (0)