Skip to content

Commit 4aa8ccf

Browse files
author
lorenzo.digiacomo
committed
feat(compatibility with react-relay 4.0.0), fix(update retainTime), feat(getStoreOffline() in environment)
1 parent 9b4f54c commit 4aa8ccf

7 files changed

+141
-394
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
React Relay Offline is a extension of [Relay](https://facebook.github.io/relay/) for offline capabilities
44

5+
## Installation
6+
7+
Install react-relay and react-relay-offline using yarn or npm:
8+
9+
```
10+
yarn add react-relay relay-offline
11+
```
12+
513

614
## Example
715

@@ -40,7 +48,8 @@ import {QueryRenderer} from 'react-relay-offline';
4048

4149
## Requirement
4250

43-
When a new node is created by mutation the id must be generated in the browser to use it in the optimistic response
51+
* Version 3.0.0 or 4.0.0 of the react-relay library
52+
* When a new node is created by mutation the id must be generated in the browser to use it in the optimistic response
4453

4554
## TODO
4655

package-lock.json

+27-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"name": "react-relay-offline",
33
"version": "0.0.2",
4+
"keywords": [
5+
"graphql",
6+
"relay",
7+
"offline"
8+
],
49
"main": "lib/index.js",
510
"license": "SEE LICENSE IN LICENSE",
611
"description": "React Relay Offline",
@@ -21,21 +26,19 @@
2126
"fbjs": "^1.0.0",
2227
"idb": "^4.0.0",
2328
"nullthrows": "^1.1.0",
24-
"react-relay": "3.0.0",
2529
"redux": "^3.7.2",
2630
"redux-thunk": "^2.3.0",
27-
"relay-runtime": "3.0.0",
2831
"uuid": "3.3.2"
2932
},
3033
"peerDependencies": {
31-
"react": "^16.5.0"
34+
"react": "^16.5.0",
35+
"react-relay": "^3.0.0 || ^4.0.0"
3236
},
3337
"devDependencies": {
34-
"@types/react-relay": "^1.3.12",
35-
"@types/relay-runtime": "^1.3.12",
3638
"typescript": "3.1.1",
3739
"react": "16.6.3",
3840
"@types/react": "16.8.14",
39-
"@types/react-dom": "16.8.4"
41+
"@types/react-dom": "16.8.4",
42+
"react-relay": "^4.0.0"
4043
}
4144
}

src/QueryRenderer.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import ReactRelayQueryFetcher from './ReactRelayQueryFetcher'
33
import { ReactRelayContext } from 'react-relay';
4+
import QueryFetcherOriginal from 'react-relay/lib/ReactRelayQueryFetcher';
45

56
import {
67
CacheConfig,
@@ -167,7 +168,7 @@ class QueryRenderer extends React.Component<Props, State> {
167168
// Re-initialize the ReactRelayQueryFetcher with callbacks.
168169
// If data has changed since constructions, this will re-render.
169170
if (this.props.query && !cached) {
170-
queryFetcher.setOnDataChange(retryCallbacks.handleDataChange);
171+
(queryFetcher as QueryFetcherOriginal).setOnDataChange(retryCallbacks.handleDataChange);
171172
}
172173
}
173174

@@ -192,8 +193,8 @@ class QueryRenderer extends React.Component<Props, State> {
192193
!areEqual(prevState.prevPropsVariables, nextProps.variables)
193194
) {
194195
const {query} = nextProps;
195-
const prevSelectionReferences = prevState.queryFetcher.getSelectionReferences();
196-
prevState.queryFetcher.disposeRequest();
196+
const prevSelectionReferences = (prevState.queryFetcher as QueryFetcherOriginal).getSelectionReferences();
197+
(prevState.queryFetcher as QueryFetcherOriginal).disposeRequest();
197198

198199
let queryFetcher;
199200
if (query) {
@@ -239,7 +240,7 @@ class QueryRenderer extends React.Component<Props, State> {
239240
}
240241

241242
componentWillUnmount(): void {
242-
this.state.queryFetcher.dispose();
243+
(this.state.queryFetcher as QueryFetcherOriginal).dispose();
243244
}
244245

245246
shouldComponentUpdate(nextProps: Props, nextState: State): boolean {
@@ -253,7 +254,7 @@ class QueryRenderer extends React.Component<Props, State> {
253254

254255
function fetchQueryAndComputeStateFromProps(
255256
props: Props,
256-
queryFetcher: ReactRelayQueryFetcher,
257+
queryFetcher: QueryFetcherOriginal,
257258
retryCallbacks: RetryCallbacks,
258259
requestCacheKey: string,
259260
): Partial<State> {
@@ -406,7 +407,7 @@ function getEmptyRenderProps(): RenderProps {
406407
function getRenderProps(
407408
error: Error,
408409
snapshot: Snapshot,
409-
queryFetcher: ReactRelayQueryFetcher,
410+
queryFetcher: QueryFetcherOriginal,
410411
retryCallbacks: RetryCallbacks,
411412
): RenderProps {
412413
return {

0 commit comments

Comments
 (0)