mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Fixes #35469 Adds `pagesDir` which is required for the Relay transform. Added a test case based on https://github.com/hanford/relay-swc-jest. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` Co-authored-by: JJ Kasper <[email protected]>
24 lines
754 B
TypeScript
24 lines
754 B
TypeScript
import { Environment, Network, RecordSource, Store } from 'relay-runtime'
|
|
|
|
async function fetchGraphQL(text, variables) {
|
|
return new Promise((next) => {
|
|
const res = () => {
|
|
return next({ data: { viewer: { user: { id: '123', name: 'Foo' } } } })
|
|
}
|
|
|
|
setTimeout(res, 1000)
|
|
})
|
|
}
|
|
|
|
// Relay passes a "params" object with the query name and text. So we define a helper function
|
|
// to call our fetchGraphQL utility with params.text.
|
|
async function fetchRelay(params, variables) {
|
|
return await fetchGraphQL(params.text, variables)
|
|
}
|
|
|
|
// Export a singleton instance of Relay Environment configured with our network function:
|
|
export default new Environment({
|
|
network: Network.create(fetchRelay),
|
|
store: new Store(new RecordSource()),
|
|
})
|