facebook / facebook/relay

Improve "Testing Relay with Preloaded Queries" docs

Open
#3,872 1 comment 10 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I followed all steps to test the `useQueryLoader` and `usePreloadedQuery` hooks, and it took me some hours to make it work. Finally, after some debugging, I found that the problem was because I needed to pass all unused variables to `loadQuery` as `null.`

This is my query:

```ts
export const usersQuery = graphql`
query UsersQuery(
$filters: UsersQueryFilters
$first: Int
$after: String
$last: Int
$before: String
) {
...UsersList_query
@arguments(
filters: $filters
first: $first
after: $after
last: $last
before: $before
)
}
`;
```

and I was passing these variables to `loadQuery`:

```ts
{
filters: { name: 'John', age: 30 },
first: 10,
};
```

After logging the operation, I saw that `after,` `last,` and `before` were `null.` So I called `loadQuery` this way, and it worked:

```ts
{
filters: { name: 'John', age: 30 },
first: 10,
after: null,
last: null,
before: null,
};
```

I suggest adding a warning after the second bullet on docs always pointing to pass variables as `null` if they're `undefined.`

![image](https://user-images.githubusercontent.com/16626980/163480407-cfef68ff-a5a4-4153-87f3-c971a63cf079.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.