Skip to content

Commit

Permalink
update version, update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
morrys committed Nov 24, 2019
1 parent f5d9601 commit 8cb74c6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 66 deletions.
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,38 @@ ReactDOM.render(
## useQuery

`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.
In addition to `query` and `variables`, `useQuery` accepts a `dataFrom` argument as part of the configuration object to determine whether it should use data cached in the
Relay store and whether to send a network request. The options are:
* `STORE_OR_NETWORK` (default): Reuse data cached in the store; if the whole query is cached, skip the network request
* `STORE_THEN_NETWORK`: Reuse data cached in the store; always send a network request.
* `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`.)
* `STORE_ONLY`: Reuse data cached in the store; never send a network request.
In addition to `query` (first argument) and `variables` (second argument), `useQuery` accepts a third argument `options`. `fetchPolicy` in `options` determine whether it should use data cached in the Relay store and whether to send a network request. The options are:
* `store-or-network` (default): Reuse data cached in the store; if the whole query is cached, skip the network request
* `store-and-network`: Reuse data cached in the store; always send a network request.
* `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`.)
* `store-only`: Reuse data cached in the store; never send a network request.

```ts
import {useQuery, graphql } from 'relay-hooks';

const query = graphql`
query appQuery($userId: String) {
user(id: $userId) {
...TodoApp_user
}
}
`;

const variables = {
userId: 'me',
};

const options = {
fetchPolicy: 'store-or-network', //default
networkCacheConfig: undefined,
}

const AppTodo = function (appProps) {
const {props, error, retry, cached} = useQuery({ query: graphql`
query appQuery($userId: String) {
user(id: $userId) {
...TodoApp_user
}
}
`,
variables: {
userId: 'me',
}});
const {props, error, retry, cached} = useQuery(query, variables, options);


if (props && props.user) {
return <TodoApp {...hooksProps} />;
return <TodoApp user={props.user} />;
} else if (error) {
return <div>{error.message}</div>;
}
Expand Down
41 changes: 24 additions & 17 deletions docs/RelayHooks-Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,37 @@ ReactDOM.render(
## useQuery

`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.
In addition to `query` and `variables`, `useQuery` accepts a `dataFrom` argument as part of the configuration object to determine whether it should use data cached in the
Relay store and whether to send a network request. The options are:
* `STORE_OR_NETWORK` (default): Reuse data cached in the store; if the whole query is cached, skip the network request
* `STORE_THEN_NETWORK`: Reuse data cached in the store; always send a network request.
* `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`.)
* `STORE_ONLY`: Reuse data cached in the store; never send a network request.
In addition to `query` (first argument) and `variables` (second argument), `useQuery` accepts a third argument `options`. `fetchPolicy` in `options` determine whether it should use data cached in the Relay store and whether to send a network request. The options are:
* `store-or-network` (default): Reuse data cached in the store; if the whole query is cached, skip the network request
* `store-and-network`: Reuse data cached in the store; always send a network request.
* `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`.)
* `store-only`: Reuse data cached in the store; never send a network request.

```ts
import {useQuery, graphql } from 'relay-hooks';

const query = graphql`
query appQuery($userId: String) {
user(id: $userId) {
...TodoApp_user
}
}
`;

const variables = {
userId: 'me',
};

const options = {
fetchPolicy: 'store-or-network', //default
networkCacheConfig: undefined,
}

const AppTodo = function (appProps) {
const {props, error, retry, cached} = useQuery({ query: graphql`
query appQuery($userId: String) {
user(id: $userId) {
...TodoApp_user
}
}
`,
variables: {
userId: 'me',
}});
const {props, error, retry, cached} = useQuery(query, variables, options);

if (props && props.user) {
return <TodoApp {...hooksProps} />;
return <TodoApp user={props.user} />;
} else if (error) {
return <div>{error.message}</div>;
}
Expand Down
43 changes: 12 additions & 31 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "relay-hooks",
"version": "2.0.0-rc.7",
"version": "2.0.0",
"keywords": [
"graphql",
"relay",
Expand Down

0 comments on commit 8cb74c6

Please sign in to comment.