Skip to content

Commit 4e88bdc

Browse files
authored
Merge pull request #64 from morrys/release-3.0.0
support relay-runtime v10.x.x
2 parents 164fa7e + 8d228ec commit 4e88bdc

16 files changed

+1396
-1370
lines changed

README.md

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -209,56 +209,59 @@ const environment = new Environment({ network, store }, persistOfflineOptions);
209209
```ts
210210
import { Store } from "react-relay-offline";
211211
import { CacheOptions } from "@wora/cache-persist";
212-
import { CacheOptionsStore } from "@wora/relay-store";
212+
import { StoreOptions } from "@wora/relay-store";
213213

214-
const persistOptionsStore: CacheOptionsStore = { defaultTTL: 10 * 60 * 1000 }; // default
215-
const persistOptionsRecords: CacheOptions = {}; // default
214+
const persistOptionsStore: CacheOptions = { };
215+
const persistOptionsRecords: CacheOptions = {};
216+
const relayStoreOptions: StoreOptions = { queryCacheExpirationTime: 10 * 60 * 1000 }; // default
216217
const recordSource = new RecordSource(persistOptionsRecords);
217-
const store = new Store(recordSource, persistOptionsStore);
218+
const store = new Store(recordSource, persistOptionsStore, relayStoreOptions);
218219
const environment = new Environment({ network, store });
219220
```
220221

221-
## QueryRenderer
222222

223-
- Add "cached" property in render function
224-
- Add "ttl" property in order to change default ttl in store
225-
- `fetchPolicy` determine whether it should use data cached in the Relay store and whether to send a network request. The options are:
226-
- `store-or-network` (default): Reuse data cached in the store; if the whole query is cached, skip the network request
227-
- `store-and-network`: Reuse data cached in the store; always send a network request.
228-
- `network-only`: Don't reuse data cached in the store; always send a network request. (This is the default behavior of Relay's existing `QueryRenderer`.)
229-
- `store-only`: Reuse data cached in the store; never send a network request.
223+
## useQuery
230224

231-
```ts
232-
import { QueryRenderer } from 'react-relay-offline';
233-
234-
<QueryRenderer
235-
environment={environment}
236-
query={query}
237-
variables={{}}
238-
fetchPolicy='store-or-network'
239-
ttl={100000}
240-
render={({ props, error, retry, cached }) => {
241-
```
225+
`useQuery` does not take an environment as an argument. Instead, it reads the environment set in the context; this also implies that it does not set any React context.
226+
In addition to `query` (first argument) and `variables` (second argument), `useQuery` accepts a third argument `options`.
242227

243-
## useQuery
228+
**options**
229+
230+
`fetchPolicy`: determine whether it should use data cached in the Relay store and whether to send a network request. The options are:
231+
* `store-or-network` (default): Reuse data cached in the store; if the whole query is cached, skip the network request
232+
* `store-and-network`: Reuse data cached in the store; always send a network request.
233+
* `network-only`: Don't reuse data cached in the store; always send a network request. (This is the default behavior of Relay's existing `QueryRenderer`.)
234+
* `store-only`: Reuse data cached in the store; never send a network request.
235+
236+
`fetchKey`: [Optional] A fetchKey can be passed to force a refetch of the current query and variables when the component re-renders, even if the variables didn't change, or even if the component isn't remounted (similarly to how passing a different key to a React component will cause it to remount). If the fetchKey is different from the one used in the previous render, the current query and variables will be refetched.
237+
238+
`networkCacheConfig`: [Optional] Object containing cache config options for the network layer. Note the the network layer may contain an additional query response cache which will reuse network responses for identical queries. If you want to bypass this cache completely, pass {force: true} as the value for this option. **Added the TTL property to configure a specific ttl for the query.**
239+
240+
`skip`: [Optional] If skip is true, the query will be skipped entirely.
241+
242+
`onComplete`: [Optional] Function that will be called whenever the fetch request has completed
244243

245244
```ts
246245
import { useQuery } from "react-relay-offline";
246+
const networkCacheConfig = {
247+
ttl: 1000
248+
}
247249
const hooksProps = useQuery(query, variables, {
248-
networkCacheConfig: cacheConfig,
250+
networkCacheConfig,
249251
fetchPolicy,
250-
ttl
251252
});
252253
```
253254

254255
## useLazyLoadQuery
255256

256257
```ts
257258
import { useQuery } from "react-relay-offline";
259+
const networkCacheConfig = {
260+
ttl: 1000
261+
}
258262
const hooksProps = useLazyLoadQuery(query, variables, {
259-
networkCacheConfig: cacheConfig,
263+
networkCacheConfig,
260264
fetchPolicy,
261-
ttl
262265
});
263266
```
264267

@@ -283,11 +286,6 @@ const isRehydrated = useRestore(environment);
283286
import { fetchQuery } from "react-relay-offline";
284287
```
285288

286-
## Mutation
287-
288-
```ts
289-
import { commitMutation, graphql } from "react-relay-offline";
290-
```
291289

292290
## Detect Network
293291

@@ -366,7 +364,7 @@ to notify any updated data in the store.
366364

367365
## Requirement
368366

369-
- Version >=8.0.0 of the react-relay library
367+
- Version >=10.1.0 of the relay-runtime library
370368
- When a new node is created by mutation the id must be generated in the browser to use it in the optimistic response
371369

372370
## License

0 commit comments

Comments
 (0)