-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathTest_nullableVariables.res
More file actions
60 lines (54 loc) · 1.48 KB
/
Copy pathTest_nullableVariables.res
File metadata and controls
60 lines (54 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module Query = %relay(`
query TestNullableVariablesQuery {
loggedInUser {
avatarUrl
}
}
`)
module Mutation = %relay(`
mutation TestNullableVariablesMutation($avatarUrl: String, $someInput: SomeInput) @rescriptRelayNullableVariables {
updateUserAvatar(avatarUrl: $avatarUrl) {
user {
avatarUrl
someRandomArgField(someInput: $someInput)
}
}
}
`)
module Test = {
@react.component
let make = () => {
let environment = RescriptRelayReact.useEnvironmentFromContext()
let query = Query.use(~variables=())
let data = query.loggedInUser
<div>
{React.string("Avatar url is " ++ data.avatarUrl->Option.getOr("-"))}
<button
onClick={_ => {
Mutation.commitMutation(
~environment,
~variables={
avatarUrl: Null.null,
someInput: Null.make({
RelaySchemaAssets_graphql.int: Null.null,
}),
},
)->RescriptRelay.Disposable.ignore
}}
>
{React.string("Change avatar URL")}
</button>
</div>
}
}
@live
let test_nullableVariables = () => {
let network = RescriptRelay.Network.makePromiseBased(~fetchFunction=RelayEnv.fetchQuery)
let environment = RescriptRelay.Environment.make(
~network,
~store=RescriptRelay.Store.make(~source=RescriptRelay.RecordSource.make()),
)
<TestProviders.Wrapper environment>
<Test />
</TestProviders.Wrapper>
}