Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# master

- Fix operations with no user supplied variables crashing when they include provided variables.

# 4.4.1

- Change name on internal fetch fn to avoid accidental shadowing.
Expand Down
41 changes: 41 additions & 0 deletions packages/rescript-relay/__tests__/Test_mutation-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,47 @@ describe("Mutation", () => {
await t.screen.findByText("First is idle");
});

test("mutation with no variables can spread a provided variable fragment", async () => {
queryMock.mockQuery({
name: "TestMutationQuery",
data: {
loggedInUser: {
id: "user-1",
firstName: "First",
lastName: "Name",
onlineStatus: "Online",
memberOf,
},
},
});

t.render(test_mutation());
await t.screen.findByText("Provided variable mutation status: -");

queryMock.mockQuery({
name: "TestMutationWithProvidedVariableFragmentMutation",
variables: {
__relay_internal__pv__ProvidedVariablesBool: true,
},
data: {
updateUserAvatar: {
user: {
id: "user-1",
someRandomArgField: "provided variable value",
},
},
},
});

ReactTestUtils.act(() => {
t.fireEvent.click(
t.screen.getByText("Run mutation with provided variable fragment")
);
});

await t.screen.findByText("Provided variable mutation status: completed");
});

test("optimistic response works", async () => {
queryMock.mockQuery({
name: "TestMutationQuery",
Expand Down
41 changes: 41 additions & 0 deletions packages/rescript-relay/__tests__/Test_mutation.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ module ComplexMutation = %relay(`
}
`)

module MutationWithProvidedVariableFragment = %relay(`
mutation TestMutationWithProvidedVariableFragmentMutation {
updateUserAvatar {
user {
...TestMutationProvidedVariable_user
}
}
}
`)

module MutationWithOnlyFragment = %relay(`
mutation TestMutationWithOnlyFragmentSetOnlineStatusMutation($onlineStatus: OnlineStatus!) @raw_response_type {
setOnlineStatus(onlineStatus: $onlineStatus) {
Expand Down Expand Up @@ -57,6 +67,15 @@ module Fragment = %relay(`
}
`)

module ProvidedVariableFragment = %relay(`
fragment TestMutationProvidedVariable_user on User
@argumentDefinitions(
bool: { type: "Boolean!", provider: "ProvidedVariables.Bool" }
) {
someRandomArgField(bool: $bool)
}
`)

module MutationWithInlineFragment = %relay(`
mutation TestMutationWithInlineFragmentSetOnlineStatusMutation($onlineStatus: OnlineStatus!) @raw_response_type {
setOnlineStatus(onlineStatus: $onlineStatus) {
Expand Down Expand Up @@ -84,6 +103,9 @@ module Test = {
let data = Fragment.use(query.loggedInUser.fragmentRefs)
let (mutate, isMutating) = Mutation.use()
let (inlineStatus, setInlineStatus) = React.useState(_ => "-")
let (providedVariableMutationStatus, setProvidedVariableMutationStatus) = React.useState(_ =>
"-"
)
let someJsonValue =
[
("foo", JSON.Encode.null),
Expand Down Expand Up @@ -114,6 +136,11 @@ module Test = {
}),
)}
<div> {React.string("Inline status: " ++ inlineStatus)} </div>
<div>
{React.string(
"Provided variable mutation status: " ++ providedVariableMutationStatus,
)}
</div>
<button
onClick={_ => {
let _ = {
Expand Down Expand Up @@ -215,6 +242,20 @@ module Test = {
>
{React.string("Change online status, complex")}
</button>
<button
onClick={_ => {
open MutationWithProvidedVariableFragment
commitMutation(~environment, ~variables=(), ~onCompleted=(response, _) => {
switch response {
| {updateUserAvatar: Some({user: Some(_)})} =>
setProvidedVariableMutationStatus(_ => "completed")
| _ => setProvidedVariableMutationStatus(_ => "missing user")
}
})->RescriptRelay.Disposable.ignore
}}
>
{React.string("Run mutation with provided variable fragment")}
</button>
<button
onClick={_ => {
let _ = {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading