Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FAQ question about prefetching #185

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -550,6 +550,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