-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
468 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule relay
updated
7 files
27 changes: 27 additions & 0 deletions
27
packages/rescript-relay/__tests__/Test_aliasedFragments-tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require("@testing-library/jest-dom/extend-expect"); | ||
const t = require("@testing-library/react"); | ||
const React = require("react"); | ||
const queryMock = require("./queryMock"); | ||
|
||
const { test_aliasedFragments } = require("./Test_aliasedFragments.bs"); | ||
|
||
describe("Aliased fragments", () => { | ||
test("basic fragments work", async () => { | ||
queryMock.mockQuery({ | ||
name: "TestAliasedFragmentsQuery", | ||
variables: { | ||
skipThing: false, | ||
}, | ||
data: { | ||
loggedInUser: { | ||
id: "user-1", | ||
firstName: "First", | ||
lastName: "Last", | ||
}, | ||
}, | ||
}); | ||
|
||
t.render(test_aliasedFragments()); | ||
await t.screen.findByText("First Last"); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
packages/rescript-relay/__tests__/Test_aliasedFragments.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module FragmentFirstName = %relay(` | ||
fragment TestAliasedFragments_userFirstName on User { | ||
firstName | ||
} | ||
`) | ||
|
||
module FragmentLastName = %relay(` | ||
fragment TestAliasedFragments_userLastName on User { | ||
lastName | ||
} | ||
`) | ||
|
||
module Query = %relay(` | ||
query TestAliasedFragmentsQuery($skipThing: Boolean!) { | ||
loggedInUser { | ||
...TestAliasedFragments_userFirstName @alias | ||
...TestAliasedFragments_userLastName @alias @skip(if: $skipThing) | ||
} | ||
} | ||
`) | ||
|
||
module Test = { | ||
@react.component | ||
let make = () => { | ||
let query = Query.use(~variables={skipThing: false}) | ||
let firstNameData = FragmentFirstName.use( | ||
query.loggedInUser.testAliasedFragments_userFirstName.fragmentRefs, | ||
) | ||
let lastNameData = FragmentLastName.useOpt( | ||
query.loggedInUser.testAliasedFragments_userLastName->Belt.Option.map(f => f.fragmentRefs), | ||
) | ||
|
||
<div> | ||
{React.string( | ||
firstNameData.firstName ++ | ||
" " ++ | ||
switch lastNameData { | ||
| None => "-" | ||
| Some({lastName}) => lastName | ||
}, | ||
)} | ||
</div> | ||
} | ||
} | ||
|
||
@live | ||
let test_aliasedFragments = () => { | ||
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> | ||
} |
257 changes: 257 additions & 0 deletions
257
packages/rescript-relay/__tests__/__generated__/TestAliasedFragmentsQuery_graphql.res
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.