Skip to content

Commit

Permalink
Added FAQ question about prefetching (connectrpc#185)
Browse files Browse the repository at this point in the history
Add docs about prefetching. 

Also adds tschecks for generated files in example.

Fixes connectrpc#117
  • Loading branch information
paul-sachs authored Oct 2, 2023
1 parent fb34ca7 commit a04327c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Connect-Query is an expansion pack for [TanStack Query](https://tanstack.com/que

- [Quickstart](#quickstart)
- [Generated Code](#generated-code)
- [Usage](#usage)
- [Connect-Query API](#connect-query-api)
- [`createQueryService`](#createqueryservice)
- [`TransportProvider`](#transportprovider)
Expand All @@ -29,7 +30,6 @@ Connect-Query is an expansion pack for [TanStack Query](https://tanstack.com/que
- [`UnaryHooks.useQuery`](#unaryhooksusequery)
- [`ConnectQueryKey`](#connectquerykey)
- [`ConnectPartialQueryKey`](#connectpartialquerykey)
- [Experimental plugin](#experimental-plugin)
- [Frequently Asked Questions](#frequently-asked-questions)
- [How do I pass other TanStack Query options?](#how-do-i-pass-other-tanstack-query-options)
- [Is this ready for production?](#is-this-ready-for-production)
Expand All @@ -40,7 +40,7 @@ Connect-Query is an expansion pack for [TanStack Query](https://tanstack.com/que
- [Do I have to use a code generator?](#do-i-have-to-use-a-code-generator)
- [What if I have a custom `Transport`?](#what-if-i-have-a-custom-transport)
- [Does this only work with React?](#does-this-only-work-with-react)
- [SolidJS Example](#solidjs-example)
- [How do I do Prefetching?](#how-do-i-do-prefetching)
- [What about Streaming?](#what-about-streaming)

## Quickstart
Expand Down Expand Up @@ -565,6 +565,20 @@ You can use Connect-Query with any TanStack variant (React, Solid, Svelte, Vue).

> Tip: If you're a TanStack Query user that uses something other than React, we'd love to hear from you. Please reach out to us on the [Buf Slack](https://buf.build/links/slack).
### How do I do Prefetching?

When you might not have access to React context, you can use the `create` series of functions and provide a transport directly. For example:

```ts
import { say } from "./gen/eliza-ElizaService_connectquery";

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

### What about Streaming?

Connect-Query currently only supports Unary RPC methods, which use a simple request/response style of communication similar to GET or POST requests in REST. This is because it aligns most closely with TanStack Query's paradigms. However, we understand that there may be use cases for Server Streaming, Client Streaming, and Bidirectional Streaming, and we're eager to hear about them.
Expand Down
1 change: 1 addition & 0 deletions examples/react/basic/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ plugins:
opt:
- target=ts
- import_extension=none
- ts_nocheck=false
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none"
// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none,ts_nocheck=false"
// @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import { CountRequest, CountResponse } from "./eliza_pb";
import { MethodKind } from "@bufbuild/protobuf";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none"
// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none,ts_nocheck=false"
// @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import {
ConverseRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none"
// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none,ts_nocheck=false"
// @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import { Nothing } from "./eliza_pb";
import { MethodKind } from "@bufbuild/protobuf";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none"
// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none,ts_nocheck=false"
// @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import { ListRequest, ListResponse } from "./eliza_pb";
import { MethodKind } from "@bufbuild/protobuf";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none"
// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none,ts_nocheck=false"
// @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import {
ConverseRequest,
Expand Down
3 changes: 1 addition & 2 deletions examples/react/basic/src/gen/eliza-Slouch_connectquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none"
// @generated by protoc-gen-connect-query v0.5.1 with parameter "target=ts,import_extension=none,ts_nocheck=false"
// @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import { Nothing } from "./eliza_pb";
import { MethodKind } from "@bufbuild/protobuf";
Expand Down

0 comments on commit a04327c

Please sign in to comment.