Skip to content

Commit

Permalink
Adding more docs (#208)
Browse files Browse the repository at this point in the history
Add missing docs on `createUnaryHooks` and sync with connect-docs repo
connectrpc/connectrpc.com#66
  • Loading branch information
paul-sachs authored Oct 4, 2023
1 parent a04327c commit 726ae30
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Connect-Query is an expansion pack for [TanStack Query](https://tanstack.com/que
- [Usage](#usage)
- [Connect-Query API](#connect-query-api)
- [`createQueryService`](#createqueryservice)
- [`createUnaryHooks`](#createunaryhooks)
- [`TransportProvider`](#transportprovider)
- [`useTransport`](#usetransport)
- [`UnaryFunctions.createData`](#unaryfunctionscreatedata)
Expand Down Expand Up @@ -121,8 +122,8 @@ export const ExampleService = {
const $queryService = createQueryService({ service: ExampleService });

export const example = {
...$queryService.say,
...createUnaryHooks($queryService.say),
...$queryService.example,
...createUnaryHooks($queryService.example),
};
```

Expand Down Expand Up @@ -177,6 +178,10 @@ const example = {
const { data, isLoading, ...etc } = useQuery(example.useQuery());
```

### `createUnaryHooks`

This creates some helper functions for unary methods that automatically include the transport from context. It's a distinct function from `createQueryService` so the core function can be separate from specific React APIs.

### `TransportProvider`

> Note: This API can only be used with React
Expand Down Expand Up @@ -280,7 +285,7 @@ const createUseMutationOptions: (options: {
};
```

`createUseMutationOptions` is intended to be used with TanStack's [`useMutation`](https://tanstack.com/query/v4/docs/react/reference/useMutation) hook. The difference is that `createUseMutationOptions` is not a hook and doesn't read from `TransportProvider` for it's transport.
`createUseMutationOptions` is intended to be used with TanStack's [`useMutation`](https://tanstack.com/query/v4/docs/react/reference/useMutation) hook. The difference is that `createUseMutationOptions` is not a hook and doesn't read from `TransportProvider` for its transport.

### `UnaryFunctions.createUseInfiniteQueryOptions`

Expand Down Expand Up @@ -308,7 +313,7 @@ const createUseInfiniteQueryOptions: <ParamKey extends keyof PlainMessage<I>>(
};
```

`createUseInfiniteQueryOptions` is intended to be used with TanStack's [`useInfiniteQuery`](https://tanstack.com/query/v4/docs/react/reference/useInfiniteQuery) hook. The difference is that `createUseInfiniteQueryOptions` is not a hook and doesn't read from `TransportProvider` for it's transport.
`createUseInfiniteQueryOptions` is intended to be used with TanStack's [`useInfiniteQuery`](https://tanstack.com/query/v4/docs/react/reference/useInfiniteQuery) hook. The difference is that `createUseInfiniteQueryOptions` is not a hook and doesn't read from `TransportProvider` for its transport.

### `UnaryFunctions.getPartialQueryKey`

Expand Down Expand Up @@ -553,7 +558,7 @@ That said, we encourage you to check out the [Connect protocol](https://connectr

### Do I have to use a code generator?

No. The code generator just calls [`createQueryService`](#createqueryservice) with the arguments already added, but you are free to do that yourself if you wish.
No. The code generator just calls [`createQueryService`](#createqueryservice) and [`createUnaryHooks`](#createunaryhooks) with the arguments already added, but you are free to do that yourself if you wish.

### What if I have a custom `Transport`?

Expand All @@ -574,7 +579,7 @@ import { say } from "./gen/eliza-ElizaService_connectquery";

function prefetch() {
return queryClient.prefetchQuery(
say.createUseQueryOptions({ sentence: "Hello" }),
say.createUseQueryOptions({ sentence: "Hello", transport: myTransport }),
);
}
```
Expand Down

0 comments on commit 726ae30

Please sign in to comment.