4 |
5 |
6 |
7 | Vite + React + TS
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.github/workflows/add-to-project.yaml:
--------------------------------------------------------------------------------
1 | name: Add issues and PRs to project
2 |
3 | on:
4 | issues:
5 | types:
6 | - opened
7 | - reopened
8 | - transferred
9 | pull_request_target:
10 | types:
11 | - opened
12 | - reopened
13 | issue_comment:
14 | types:
15 | - created
16 |
17 | jobs:
18 | call-workflow-add-to-project:
19 | name: Call workflow to add issue to project
20 | uses: connectrpc/base-workflows/.github/workflows/add-to-project.yaml@main
21 | secrets: inherit
22 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/buf.gen.yaml:
--------------------------------------------------------------------------------
1 | # buf.gen.yaml defines a local generation template.
2 | # For details, see https://buf.build/docs/configuration/v2/buf-gen-yaml
3 | version: v2
4 | inputs:
5 | - proto_file: eliza.proto
6 | # Deletes the directories specified in the `out` field for all plugins before running code generation.
7 | clean: true
8 | plugins:
9 | - local: protoc-gen-es
10 | out: src/gen
11 | opt:
12 | - target=ts
13 | - local: protoc-gen-connect-query
14 | out: src/gen
15 | opt:
16 | - target=ts
17 |
--------------------------------------------------------------------------------
/.github/workflows/pr-title.yaml:
--------------------------------------------------------------------------------
1 | name: Lint PR Title
2 | # Prevent writing to the repository using the CI token.
3 | # Ref: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions
4 | permissions:
5 | pull-requests: read
6 | on:
7 | pull_request:
8 | # By default, a workflow only runs when a pull_request's activity type is opened,
9 | # synchronize, or reopened. We explicity override here so that PR titles are
10 | # re-linted when the PR text content is edited.
11 | types:
12 | - opened
13 | - edited
14 | - reopened
15 | - synchronize
16 | jobs:
17 | lint:
18 | uses: bufbuild/base-workflows/.github/workflows/pr-title.yaml@main
19 |
--------------------------------------------------------------------------------
/packages/connect-query/README.md:
--------------------------------------------------------------------------------
1 | # @connectrpc/connect-query
2 |
3 | This is the runtime library package for Connect-Query. You'll find its code generator at [@connectrpc/protoc-gen-connect-query](https://www.npmjs.com/package/@connectrpc/protoc-gen-connect-query).
4 |
5 | Connect-Query is a wrapper around [TanStack Query](https://tanstack.com/query) (react-query), written in TypeScript and thoroughly tested. It enables effortless communication with servers that speak the [Connect Protocol](https://connectrpc.com/docs/protocol).
6 |
7 | To get started, head over to the [docs](https://github.com/connectrpc/connect-query-es) for a tutorial, or take a look at [our examples](https://github.com/connectrpc/connect-query-es/tree/main/examples).
8 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/src/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | ///
16 |
--------------------------------------------------------------------------------
/scripts/find-workspace-version.js:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import { findWorkspaceVersion } from "./utils.js";
16 |
17 | process.stdout.write(`${findWorkspaceVersion("packages")}\n`);
18 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "allowJs": false,
4 | "allowSyntheticDefaultImports": true,
5 | "esModuleInterop": false,
6 | "exactOptionalPropertyTypes": true,
7 | "forceConsistentCasingInFileNames": true,
8 | "isolatedModules": true,
9 | "jsx": "react-jsx",
10 | "lib": ["DOM", "DOM.Iterable", "ESNext"],
11 | "module": "ESNext",
12 | "moduleResolution": "Node",
13 | "noEmit": true,
14 | "resolveJsonModule": true,
15 | "skipLibCheck": true,
16 | "strict": true,
17 | "target": "ESNext",
18 | "useDefineForClassFields": true,
19 | "types": ["node"],
20 | "declaration": true // necessary to check if generated code can be published
21 | },
22 | "include": ["src", "./*.config.ts", "__mocks__"]
23 | }
24 |
--------------------------------------------------------------------------------
/packages/test-utils/proto/proto2.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | syntax = "proto2";
16 | package test;
17 |
18 | message Proto2Message {
19 | optional string string_field = 1;
20 | optional int32 int32_field = 3;
21 | }
22 |
--------------------------------------------------------------------------------
/packages/protoc-gen-connect-query/src/utils.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import type { createEcmaScriptPlugin } from "@bufbuild/protoplugin";
16 |
17 | /**
18 | * Extracts the type of PluginInit from @bufbuild/protoplugin
19 | */
20 | export type PluginInit = Required[0]>;
21 |
--------------------------------------------------------------------------------
/tsconfig.base.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "lib": [
5 | "ES2017",
6 | // DOM for the fetch and streams API
7 | "DOM"
8 | ],
9 | "esModuleInterop": false,
10 | "forceConsistentCasingInFileNames": true,
11 | "strict": true,
12 | "noImplicitAny": true,
13 | "strictNullChecks": true,
14 | "strictFunctionTypes": true,
15 | "strictBindCallApply": true,
16 | "strictPropertyInitialization": true,
17 | "noImplicitThis": true,
18 | "useUnknownInCatchVariables": true,
19 | "noUnusedLocals": true,
20 | "noImplicitReturns": true,
21 | "noFallthroughCasesInSwitch": true,
22 | "noImplicitOverride": true,
23 |
24 | // We need node's module resolution, so we do not have to skip lib checks
25 | "moduleResolution": "Node16",
26 | "module": "Node16",
27 | "verbatimModuleSyntax": true,
28 | "skipLibCheck": false
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/src/css.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | export const borderRadius = 6;
16 | export const margin = 6;
17 | export const padding = 6;
18 | export const boxShadow = "0px 1px 2px rgba(15, 16, 77, 0.05)";
19 | export const border = "1px solid #E4E9EF";
20 |
21 | export const lightBlue = "#C4E8FC";
22 | export const white = "#FFFFFF";
23 |
--------------------------------------------------------------------------------
/packages/test-utils/proto/list.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | syntax = "proto3";
16 |
17 | service ListService {
18 | rpc List(ListRequest) returns (ListResponse);
19 | }
20 |
21 | message ListRequest {
22 | int64 page = 1;
23 | bool preview = 2;
24 | }
25 |
26 | message ListResponse {
27 | int64 page = 1;
28 | repeated string items = 2;
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/turbo.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://turbo.build/schema.json",
3 | "tasks": {
4 | "build": {
5 | "dependsOn": ["^build", "generate"],
6 | "outputs": ["dist/**"]
7 | },
8 | "generate": {
9 | "dependsOn": ["^build"],
10 | "outputs": ["src/gen/**"]
11 | },
12 | "test": {
13 | "dependsOn": ["build"],
14 | "cache": false
15 | },
16 | "format": {},
17 | "license-header": {
18 | "dependsOn": ["generate"]
19 | },
20 | "lint": {
21 | "dependsOn": ["format", "^build", "generate"]
22 | },
23 | "attw": {
24 | "dependsOn": ["build"]
25 | },
26 | "//#format": {
27 | "inputs": ["$TURBO_DEFAULT$", "!packages/**", "package-lock.json"]
28 | },
29 | "//#license-header": {
30 | "inputs": ["$TURBO_DEFAULT$", "!packages/**"]
31 | },
32 | "//#lint": {
33 | "dependsOn": ["format"],
34 | "inputs": ["$TURBO_DEFAULT$", "!packages/**", "package-lock.json"]
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/packages/test-utils/proto/bigint.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | syntax = "proto3";
16 |
17 | import "google/protobuf/empty.proto";
18 |
19 | service BigIntService {
20 | rpc Count(CountRequest) returns (CountResponse);
21 | rpc GetCount(google.protobuf.Empty) returns (CountResponse);
22 | }
23 |
24 | message CountRequest {
25 | int64 add = 1;
26 | }
27 |
28 | message CountResponse {
29 | int64 count = 1;
30 | }
31 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/src/page.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import type { FC, PropsWithChildren } from "react";
16 |
17 | import { margin } from "./css";
18 |
19 | /**
20 | * The wrapper for the whole page
21 | */
22 | export const Page: FC = ({ children }) => (
23 |
30 | {children}
31 |
32 | );
33 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/vite.config.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import react from "@vitejs/plugin-react";
16 | import { defineConfig } from "vitest/config";
17 |
18 | // https://vitejs.dev/config/
19 | export default defineConfig({
20 | plugins: [react()],
21 | test: {
22 | environment: "jsdom",
23 | typecheck: {
24 | enabled: true,
25 | // Modified to typecheck definition files as well as source files
26 | include: ["**/*.{test,spec}?(-d).?(c|m)[jt]s?(x)"],
27 | },
28 | },
29 | });
30 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/src/gen/eliza-ElizaService_connectquery.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // @generated by protoc-gen-connect-query v2.2.0 with parameter "target=ts"
16 | // @generated from file eliza.proto (package connectrpc.eliza.v1, syntax proto3)
17 | /* eslint-disable */
18 |
19 | import { ElizaService } from "./eliza_pb";
20 |
21 | /**
22 | * Say is a unary RPC. Eliza responds to the prompt with a single sentence.
23 | *
24 | * @generated from rpc connectrpc.eliza.v1.ElizaService.Say
25 | */
26 | export const say = ElizaService.method.say;
27 |
--------------------------------------------------------------------------------
/cspell.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "words": [
3 | "Deno",
4 | "Dimitri",
5 | "Mitropoulos",
6 | "Quickstart",
7 | "Stamm",
8 | "Timo",
9 | "Vindaloo",
10 | "Weizenbaum's",
11 | "attw",
12 | "backoffs",
13 | "bufbuild",
14 | "codegen",
15 | "connectquery",
16 | "connectrpc",
17 | "connectweb",
18 | "descriptorset",
19 | "excalidraw",
20 | "idempotence",
21 | "idempotency",
22 | "inferencing",
23 | "invalidators",
24 | "keyof",
25 | "lcov",
26 | "nocheck",
27 | "pnpm",
28 | "preconfigured",
29 | "proto",
30 | "protobuf",
31 | "protoc",
32 | "protofile",
33 | "protoplugin",
34 | "tanstack",
35 | "todos",
36 | "tsdoc",
37 | "corepack",
38 | "printables",
39 | "arethetypeswrong",
40 | "oneof",
41 | "typesafe",
42 | "setversion",
43 | "getversion",
44 | "postsetversion",
45 | "postgenerate",
46 | "npmjs"
47 | ],
48 | "ignorePaths": [
49 | "**/*.svg",
50 | "**/*.ai",
51 | "**/pnpm-lock.yaml",
52 | "*.excalidraw",
53 | "**/gen",
54 | "**/snapshots",
55 | "**/*.css",
56 | "**/*.xml",
57 | "**/tsconfig.vitest-temp.json"
58 | ]
59 | }
60 |
--------------------------------------------------------------------------------
/packages/connect-query/src/index.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | export * from "@connectrpc/connect-query-core";
16 | export { useTransport, TransportProvider } from "./use-transport.js";
17 | export {
18 | useInfiniteQuery,
19 | useSuspenseInfiniteQuery,
20 | } from "./use-infinite-query.js";
21 | export { useQuery, useSuspenseQuery } from "./use-query.js";
22 | export type { UseMutationOptions } from "./use-mutation.js";
23 | export { useMutation } from "./use-mutation.js";
24 | export type { UseInfiniteQueryOptions } from "./use-infinite-query.js";
25 | export type { UseQueryOptions } from "./use-query.js";
26 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@connectrpc/connect-query-example-basic",
3 | "version": "2.2.0",
4 | "private": true,
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "generate": "buf generate",
9 | "license-header": "license-header",
10 | "test": "vitest --run",
11 | "test:watch": "vitest --watch --ui",
12 | "lint": "eslint --max-warnings 0 .",
13 | "format": "prettier --write . '!src/gen'"
14 | },
15 | "dependencies": {
16 | "@bufbuild/buf": "1.54.0",
17 | "@bufbuild/protobuf": "^2.5.1",
18 | "@bufbuild/protoc-gen-es": "^2.5.1",
19 | "@connectrpc/connect": "^2.0.2",
20 | "@connectrpc/connect-query": "^2.2.0",
21 | "@connectrpc/connect-web": "^2.0.2",
22 | "@connectrpc/protoc-gen-connect-query": "^2.2.0",
23 | "@tanstack/react-query": "^5.79.0",
24 | "@tanstack/react-query-devtools": "^5.79.0",
25 | "@testing-library/jest-dom": "^6.6.3",
26 | "@testing-library/react": "^16.3.0",
27 | "@types/react": "^19.1.6",
28 | "@types/react-dom": "^19.1.5",
29 | "@vitejs/plugin-react": "^4.5.0",
30 | "react": "^19.1.0",
31 | "react-dom": "^19.1.0",
32 | "typescript": "^5.8.3",
33 | "vite": "^6.3.5"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/packages/protoc-gen-connect-query/src/protoc-gen-connect-query-plugin.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import { createEcmaScriptPlugin } from "@bufbuild/protoplugin";
16 |
17 | import { version } from "../package.json";
18 | import { generateDts } from "./generateDts.js";
19 | import { generateTs } from "./generateTs.js";
20 |
21 | export const protocGenConnectQuery = createEcmaScriptPlugin({
22 | name: "protoc-gen-connect-query",
23 | version: `v${String(version)}`,
24 | generateTs,
25 |
26 | // The generated TypeScript output is completely valid JavaScript since all the types are inferred
27 | generateJs: generateTs,
28 | generateDts,
29 | });
30 |
--------------------------------------------------------------------------------
/packages/connect-query/vite.config.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import { defineConfig } from "vitest/config";
16 |
17 | // https://vitejs.dev/config/
18 | export default defineConfig({
19 | test: {
20 | environment: "jsdom",
21 | typecheck: {
22 | enabled: true,
23 | // Modified to typecheck definition files as well as source files
24 | include: ["**/*.{test,spec}?(-d).?(c|m)[jt]s?(x)"],
25 | },
26 | coverage: {
27 | provider: "istanbul",
28 | thresholds: {
29 | branches: 100,
30 | functions: 100,
31 | lines: 100,
32 | statements: 100,
33 | },
34 | },
35 | },
36 | });
37 |
--------------------------------------------------------------------------------
/packages/connect-query-core/vite.config.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import { defineConfig } from "vitest/config";
16 |
17 | // https://vitejs.dev/config/
18 | export default defineConfig({
19 | test: {
20 | environment: "jsdom",
21 | typecheck: {
22 | enabled: true,
23 | // Modified to typecheck definition files as well as source files
24 | include: ["**/*.{test,spec}?(-d).?(c|m)[jt]s?(x)"],
25 | },
26 | coverage: {
27 | provider: "istanbul",
28 | thresholds: {
29 | branches: 100,
30 | functions: 100,
31 | lines: 100,
32 | statements: 100,
33 | },
34 | },
35 | },
36 | });
37 |
--------------------------------------------------------------------------------
/.github/dependabot.yaml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "github-actions"
4 | directory: "/"
5 | schedule:
6 | interval: "monthly"
7 | day: "monday"
8 | timezone: UTC
9 | time: "07:00"
10 | - package-ecosystem: "npm"
11 | directory: "/"
12 | schedule:
13 | interval: "monthly"
14 | day: "monday"
15 | timezone: UTC
16 | time: "07:00"
17 | open-pull-requests-limit: 50
18 | groups:
19 | connectRelated:
20 | patterns:
21 | - "@connectrpc/*"
22 | - "@bufbuild/*"
23 | devDependencies:
24 | patterns:
25 | - "@arethetypeswrong/*"
26 | - "@testing-library/*"
27 | - "@types/*"
28 | - "@typescript-eslint/*"
29 | - "@vitejs/*"
30 | - "cspell"
31 | - "eslint*"
32 | - "jest-mock"
33 | - "jest"
34 | - "prettier"
35 | - "react-dom"
36 | - "react"
37 | - "ts-jest"
38 | - "ts-node"
39 | - "turbo"
40 | - "typescript"
41 | - "vite"
42 | - "vitest"
43 | - "@vitest/*"
44 | reactQuery:
45 | patterns:
46 | - "@tanstack/react-query"
47 | - "@tanstack/react-query-devtools"
48 | - "@tanstack/query-core"
49 |
--------------------------------------------------------------------------------
/scripts/gh-diffcheck.js:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import { execSync } from "node:child_process";
16 |
17 | if (gitUncommitted()) {
18 | process.stdout.write(
19 | "::error::Uncommitted changes found. Please make sure this branch is up to date, and run the command locally (for example `npx turbo format`). " +
20 | "Verify the changes are what you want and commit them.\n",
21 | );
22 | execSync("git --no-pager diff", {
23 | stdio: "inherit",
24 | });
25 | process.exit(1);
26 | }
27 |
28 | /**
29 | * @returns {boolean}
30 | */
31 | function gitUncommitted() {
32 | const out = execSync("git status --porcelain", {
33 | encoding: "utf-8",
34 | });
35 | return out.trim().length > 0;
36 | }
37 |
--------------------------------------------------------------------------------
/packages/test-utils/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "test-utils",
3 | "private": true,
4 | "version": "2.2.0",
5 | "type": "module",
6 | "scripts": {
7 | "generate": "buf generate",
8 | "postgenerate": "license-header gen",
9 | "prebuild": "rm -rf ./dist/*",
10 | "build": "npm run build:cjs && npm run build:esm",
11 | "build:cjs": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
12 | "build:esm": "tsc --project tsconfig.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
13 | "format": "prettier --write --ignore-unknown '.' '!dist' '!src/gen'",
14 | "license-header": "license-header --ignore 'src/gen/**'",
15 | "lint": "eslint --max-warnings 0 ."
16 | },
17 | "main": "./dist/cjs/index.js",
18 | "types": "./dist/cjs/index.d.ts",
19 | "exports": {
20 | ".": {
21 | "import": "./dist/esm/index.js"
22 | },
23 | "./gen/*": {
24 | "import": "./dist/esm/gen/*"
25 | }
26 | },
27 | "devDependencies": {
28 | "@bufbuild/buf": "^1.54.0",
29 | "@bufbuild/protobuf": "^2.5.1",
30 | "@bufbuild/protoc-gen-es": "^2.5.1",
31 | "@connectrpc/connect": "^2.0.2",
32 | "@connectrpc/connect-web": "^2.0.2",
33 | "@types/react": "^19.1.6",
34 | "react": "^19.1.0"
35 | },
36 | "files": [
37 | "dist/**"
38 | ]
39 | }
40 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/packages/connect-query-core/src/create-infinite-query-options.test.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import { mockEliza } from "test-utils";
16 | import { ListService } from "test-utils/gen/list_pb.js";
17 | import { describe, expect, expectTypeOf, it } from "vitest";
18 |
19 | import { createInfiniteQueryOptions, skipToken } from "./index.js";
20 |
21 | const listMethod = ListService.method.list;
22 |
23 | const mockedElizaTransport = mockEliza();
24 |
25 | describe("createInfiniteQueryOptions", () => {
26 | it("honors skipToken", () => {
27 | const opt = createInfiniteQueryOptions(listMethod, skipToken, {
28 | transport: mockedElizaTransport,
29 | getNextPageParam: (lastPage) => lastPage.page + 1n,
30 | pageParamKey: "page",
31 | });
32 | expect(opt.queryFn).toBe(skipToken);
33 | expectTypeOf(opt.queryFn).toEqualTypeOf(skipToken);
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/packages/test-utils/proto/eliza.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | syntax = "proto3";
16 |
17 | package connectrpc.eliza.v1;
18 |
19 | // ElizaService provides a way to talk to Eliza, a port of the DOCTOR script
20 | // for Joseph Weizenbaum's original ELIZA program. Created in the mid-1960s at
21 | // the MIT Artificial Intelligence Laboratory, ELIZA demonstrates the
22 | // superficiality of human-computer communication. DOCTOR simulates a
23 | // psychotherapist, and is commonly found as an Easter egg in emacs
24 | // distributions.
25 | service ElizaService {
26 | // Say is a unary RPC. Eliza responds to the prompt with a single sentence.
27 | rpc Say(SayRequest) returns (SayResponse) {}
28 | }
29 |
30 | // SayRequest is a single-sentence request.
31 | message SayRequest {
32 | string sentence = 1;
33 | }
34 |
35 | // SayResponse is a single-sentence response.
36 | message SayResponse {
37 | string sentence = 1;
38 | }
39 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/eliza.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | syntax = "proto3";
16 |
17 | package connectrpc.eliza.v1;
18 |
19 | // ElizaService provides a way to talk to Eliza, a port of the DOCTOR script
20 | // for Joseph Weizenbaum's original ELIZA program. Created in the mid-1960s at
21 | // the MIT Artificial Intelligence Laboratory, ELIZA demonstrates the
22 | // superficiality of human-computer communication. DOCTOR simulates a
23 | // psychotherapist, and is commonly found as an Easter egg in emacs
24 | // distributions.
25 | service ElizaService {
26 | // Say is a unary RPC. Eliza responds to the prompt with a single sentence.
27 | rpc Say(SayRequest) returns (SayResponse) {}
28 | }
29 |
30 | // SayRequest is a single-sentence request.
31 | message SayRequest {
32 | string sentence = 1;
33 | }
34 |
35 | // SayResponse is a single-sentence response.
36 | message SayResponse {
37 | string sentence = 1;
38 | }
39 |
--------------------------------------------------------------------------------
/packages/protoc-gen-connect-query/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@connectrpc/protoc-gen-connect-query",
3 | "version": "2.2.0",
4 | "description": "Code generator for connect-query",
5 | "license": "Apache-2.0",
6 | "sideEffects": false,
7 | "repository": {
8 | "type": "git",
9 | "url": "https://github.com/connectrpc/connect-query-es.git",
10 | "directory": "packages/protoc-gen-connect-query"
11 | },
12 | "files": [
13 | "dist/**"
14 | ],
15 | "bin": {
16 | "protoc-gen-connect-query": "bin/protoc-gen-connect-query"
17 | },
18 | "engines": {
19 | "node": ">=20"
20 | },
21 | "scripts": {
22 | "prebuild": "rm -rf ./dist/*",
23 | "build": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs",
24 | "format": "prettier --write --ignore-unknown '.' '!dist'",
25 | "license-header": "license-header",
26 | "lint": "eslint --max-warnings 0 ."
27 | },
28 | "preferUnplugged": true,
29 | "devDependencies": {
30 | "@bufbuild/buf": "1.54.0",
31 | "@bufbuild/protoc-gen-es": "^2.5.1",
32 | "@connectrpc/connect": "^2.0.2",
33 | "@connectrpc/connect-query": "^2.2.0",
34 | "@tanstack/react-query": "^5.79.0",
35 | "typescript": "^5.8.3"
36 | },
37 | "dependencies": {
38 | "@bufbuild/protobuf": "^2.5.1",
39 | "@bufbuild/protoplugin": "^2.2.1"
40 | },
41 | "peerDependencies": {
42 | "@bufbuild/protoc-gen-es": "2.x"
43 | },
44 | "peerDependenciesMeta": {
45 | "@bufbuild/protoc-gen-es": {
46 | "optional": true
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/packages/connect-query-core/src/index.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | export type { ConnectQueryKey } from "./connect-query-key.js";
16 | export { createConnectQueryKey } from "./connect-query-key.js";
17 | export { createProtobufSafeUpdater } from "./utils.js";
18 | export type { ConnectUpdater } from "./utils.js";
19 | export { callUnaryMethod } from "./call-unary-method.js";
20 | export { createInfiniteQueryOptions } from "./create-infinite-query-options.js";
21 | export type {
22 | ConnectInfiniteQueryOptions,
23 | InfiniteQueryOptionsWithSkipToken,
24 | InfiniteQueryOptions,
25 | } from "./create-infinite-query-options.js";
26 | export { createQueryOptions } from "./create-query-options.js";
27 | export type {
28 | QueryOptions,
29 | QueryOptionsWithSkipToken,
30 | } from "./create-query-options.js";
31 | export { addStaticKeyToTransport } from "./transport-key.js";
32 | export type { SkipToken } from "@tanstack/query-core";
33 | export { skipToken } from "@tanstack/query-core";
34 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/src/main.test.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import "@testing-library/jest-dom/vitest";
16 |
17 | import { createRouterTransport } from "@connectrpc/connect";
18 | import { render, screen } from "@testing-library/react";
19 | import { describe, expect, it } from "vitest";
20 |
21 | import * as methods from "./gen/eliza-ElizaService_connectquery";
22 | import Main from "./main";
23 |
24 | describe("Application", () => {
25 | it("should show success status and response data", async () => {
26 | const transport = createRouterTransport(({ rpc }) => {
27 | rpc(methods.say, () => ({
28 | sentence: "Hello, world!",
29 | }));
30 | });
31 | render();
32 | const text = await screen.findByText("Status: success");
33 | expect(text).toBeInTheDocument();
34 | const response = await screen.findByLabelText("data");
35 | expect(response).toHaveTextContent(
36 | '{"$typeName":"connectrpc.eliza.v1.SayResponse","sentence":"Hello, world!"}',
37 | );
38 | });
39 | });
40 |
--------------------------------------------------------------------------------
/packages/connect-query-core/src/call-unary-method.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import type {
16 | DescMessage,
17 | DescMethodUnary,
18 | MessageInitShape,
19 | MessageShape,
20 | } from "@bufbuild/protobuf";
21 | import { create } from "@bufbuild/protobuf";
22 | import type { Transport } from "@connectrpc/connect";
23 |
24 | /**
25 | * Call a unary method given its signature and input.
26 | */
27 | // eslint-disable-next-line @typescript-eslint/max-params -- 4th param is optional
28 | export async function callUnaryMethod<
29 | I extends DescMessage,
30 | O extends DescMessage,
31 | >(
32 | transport: Transport,
33 | schema: DescMethodUnary,
34 | input: MessageInitShape | undefined,
35 | options?: {
36 | signal?: AbortSignal;
37 | headers?: HeadersInit;
38 | },
39 | ): Promise> {
40 | const result = await transport.unary(
41 | schema,
42 | options?.signal,
43 | undefined,
44 | options?.headers,
45 | input ?? create(schema.input),
46 | undefined,
47 | );
48 | return result.message;
49 | }
50 |
--------------------------------------------------------------------------------
/packages/test-utils/proto/proto3.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | syntax = "proto3";
16 | package test;
17 |
18 | // Note: We do not exhaust all field types
19 | message Proto3Message {
20 | string string_field = 1;
21 | bytes bytes_field = 2;
22 | int32 int32_field = 3;
23 | int64 int64_field = 4;
24 | double double_field = 5;
25 | bool bool_field = 6;
26 | Proto3Enum enum_field = 7;
27 | Proto3Message message_field = 8;
28 |
29 | optional string optional_string_field = 9;
30 |
31 | repeated string repeated_string_field = 17;
32 | repeated Proto3Message repeated_message_field = 18;
33 | repeated Proto3Enum repeated_enum_field = 19;
34 |
35 | oneof either {
36 | string oneof_string_field = 31;
37 | int32 oneof_int32_field = 33;
38 | }
39 |
40 | map map_string_int64_field = 39;
41 | map map_string_message_field = 40;
42 | map map_string_enum_field = 41;
43 | }
44 |
45 | enum Proto3Enum {
46 | PROTO3_ENUM_UNSPECIFIED = 0;
47 | PROTO3_ENUM_YES = 1;
48 | PROTO3_ENUM_NO = 2;
49 | }
50 |
--------------------------------------------------------------------------------
/packages/connect-query-core/src/structural-sharing.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import { type DescMessage, equals, isMessage } from "@bufbuild/protobuf";
16 | import { replaceEqualDeep } from "@tanstack/query-core";
17 |
18 | /**
19 | * Returns a simplistic implementation for "structural sharing" for a Protobuf
20 | * message.
21 | *
22 | * To keep references intact between re-renders, we return the old version if it
23 | * equals the new version.
24 | *
25 | * See https://tanstack.com/query/latest/docs/framework/react/guides/render-optimizations#structural-sharing
26 | */
27 | export function createStructuralSharing(
28 | schema: DescMessage,
29 | // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents -- matching the @tanstack/react-query types
30 | ): (oldData: unknown | undefined, newData: unknown) => unknown {
31 | return function (oldData, newData) {
32 | if (!isMessage(oldData) || !isMessage(newData)) {
33 | return replaceEqualDeep(oldData, newData);
34 | }
35 | if (!equals(schema, oldData, newData)) {
36 | return newData;
37 | }
38 | return oldData;
39 | };
40 | }
41 |
--------------------------------------------------------------------------------
/scripts/utils.js:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import { readdirSync, readFileSync, existsSync } from "node:fs";
16 | import { join } from "node:path";
17 |
18 | /**
19 | * Retrieves the workspace version from the package directory.
20 | *
21 | * @param {string} packagesDir
22 | * @returns {string}
23 | */
24 | export function findWorkspaceVersion(packagesDir) {
25 | let version = undefined;
26 | for (const entry of readdirSync(packagesDir, { withFileTypes: true })) {
27 | if (!entry.isDirectory()) {
28 | continue;
29 | }
30 | const path = join(packagesDir, entry.name, "package.json");
31 | if (existsSync(path)) {
32 | const pkg = JSON.parse(readFileSync(path, "utf-8"));
33 | if (pkg.private === true) {
34 | continue;
35 | }
36 | if (!pkg.version) {
37 | throw new Error(`${path} is missing "version"`);
38 | }
39 | if (version === undefined) {
40 | version = pkg.version;
41 | } else if (version !== pkg.version) {
42 | throw new Error(`${path} has unexpected version ${pkg.version}`);
43 | }
44 | }
45 | }
46 | if (version === undefined) {
47 | throw new Error(`unable to find workspace version`);
48 | }
49 | return version;
50 | }
51 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/src/main.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import "./index.css";
16 |
17 | import type { Transport } from "@connectrpc/connect";
18 | import { TransportProvider } from "@connectrpc/connect-query";
19 | import { createConnectTransport } from "@connectrpc/connect-web";
20 | import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
21 | import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
22 | import * as ReactDOM from "react-dom/client";
23 |
24 | import { Example } from "./example";
25 |
26 | const queryClient = new QueryClient();
27 |
28 | /**
29 | * The application root
30 | */
31 | export default function App({ transport }: { transport?: Transport }) {
32 | const finalTransport =
33 | transport ??
34 | createConnectTransport({
35 | baseUrl: "https://demo.connectrpc.com",
36 | });
37 | return (
38 |
39 |
40 |
41 |
42 |
43 |
44 | );
45 | }
46 |
47 | const rootElement = document.getElementById("root");
48 | if (rootElement) {
49 | ReactDOM.createRoot(rootElement).render();
50 | }
51 |
--------------------------------------------------------------------------------
/packages/test-utils/src/gen/proto2_pb.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // @generated by protoc-gen-es v2.6.2 with parameter "target=ts"
16 | // @generated from file proto2.proto (package test, syntax proto2)
17 | /* eslint-disable */
18 |
19 | import type { GenFile, GenMessage } from "@bufbuild/protobuf/codegenv2";
20 | import { fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2";
21 | import type { Message } from "@bufbuild/protobuf";
22 |
23 | /**
24 | * Describes the file proto2.proto.
25 | */
26 | export const file_proto2: GenFile = /*@__PURE__*/
27 | fileDesc("Cgxwcm90bzIucHJvdG8SBHRlc3QiOgoNUHJvdG8yTWVzc2FnZRIUCgxzdHJpbmdfZmllbGQYASABKAkSEwoLaW50MzJfZmllbGQYAyABKAU");
28 |
29 | /**
30 | * @generated from message test.Proto2Message
31 | */
32 | export type Proto2Message = Message<"test.Proto2Message"> & {
33 | /**
34 | * @generated from field: optional string string_field = 1;
35 | */
36 | stringField: string;
37 |
38 | /**
39 | * @generated from field: optional int32 int32_field = 3;
40 | */
41 | int32Field: number;
42 | };
43 |
44 | /**
45 | * Describes the message test.Proto2Message.
46 | * Use `create(Proto2MessageSchema)` to create a new message.
47 | */
48 | export const Proto2MessageSchema: GenMessage = /*@__PURE__*/
49 | messageDesc(file_proto2, 0);
50 |
51 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/src/example.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import { useQuery } from "@connectrpc/connect-query";
16 | import type { FC } from "react";
17 |
18 | import { Data, Datum } from "./datum";
19 | import { say } from "./gen/eliza-ElizaService_connectquery";
20 | import { Indicator, Indicators } from "./indicator";
21 | import { Page } from "./page";
22 |
23 | /**
24 | * This example demonstrates a basic usage of Connect-Query with `useQuery`
25 | */
26 | export const Example: FC = () => {
27 | const { status, fetchStatus, error, data } = useQuery(say, {
28 | sentence: "Hello",
29 | });
30 |
31 | return (
32 |
33 | Status: {status}
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | );
50 | };
51 |
--------------------------------------------------------------------------------
/packages/examples/react/basic/src/indicator.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2021-2023 The Connect Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | import type { FC, ReactNode } from "react";
16 |
17 | import { border, borderRadius, boxShadow, margin } from "./css";
18 |
19 | /**
20 | * a single Indicator
21 | */
22 | export const Indicator = ({
23 | label,
24 | parent,
25 | }: {
26 | label: U;
27 | parent: T;
28 | }) => {
29 | const height = "50px";
30 | const active = label === parent;
31 |
32 | return (
33 |