forked from connectrpc/connect-query-es
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## What's Changed * V1 API: Wrapping react-query by @paul-sachs in connectrpc#224 ## V1 Release 🚀 Introducing a whole new API for connect-query. This API ties itself more tightly with the fantastic `@tanstack/react-query` in order to improve developer experience and reduce bundle size. At the core of this change is the new `MethodUnaryDescriptor` type, which is essentially just a self contained description of a service method. The new code generator just outputs one of these per method and those are passed to the hooks/methods. This new additional type brings a huge level of flexibility about how we write additional methods, and it's trivial to write your own hooks/methods around these simple types. ### Example usage ```tsx import { useQuery } from "@connectrpc/connect-react-query"; import { say } from "./gen/eliza-ElizaService_connectquery"; ... const { data } = useQuery(say); ``` ### Breaking changes - `use*Query` hooks now return data instead of just options. - Many `create*` methods have been removed. - `protoc-gen-connect-query` now outputs very simple method descriptors instead of a bunch of hooks per method. ### Reasoning There are a number of reasons we've decided to make this major breaking change. 1. The API surface is much smaller, leading to less confusion about how to use each method. 2. Smaller core code size and more modular organization leads to better tree shaking (since each generated method doesn't come along with a generated hook). 3. Package names are now explicit about their dependencies, making it easier to develop other packages based on these packages/generated code. 4. More tightly integrating with `@tanstack/react-query@5` provides better usage of Suspense versions of the API. 5. New generated code is easier to expand and build your own custom hooks for. ### Migration The migration process is easy but manual: #### Before ```tsx import { getUserOrganization } from "@apigen/org/alpha/registry/v1alpha1/organization-OrganizationService_connectquery"; import { useQuery } from "@tanstack/react-query"; ... const getUserOrganizationQuery = useQuery({ ...getUserOrganization.useQuery({ userId: currentUser?.id, organizationId, }), useErrorBoundary: false, enabled: currentUser !== null, }); ``` #### After ```tsx import { getUserOrganization } from "@apigen/org/alpha/registry/v1alpha1/organization-OrganizationService_connectquery"; import { useQuery } from "@connectrpc/connect-react-query"; ... const getUserOrganizationQuery = useQuery(getUserOrganization, { userId: currentUser?.id, organizationId, }, { useErrorBoundary: false, enabled: currentUser !== null } }); ``` ## New Contributors * @chrispine made their first contribution in connectrpc#243 **Full Changelog**: connectrpc/connect-query-es@v0.6.0...v1.0.0
- Loading branch information
1 parent
84b474a
commit c6f294c
Showing
12 changed files
with
13 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/protoc-gen-connect-query/bin/protoc-gen-connect-query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#!/usr/bin/env node | ||
|
||
const { runNodeJs } = require('@bufbuild/protoplugin'); | ||
const { runNodeJs } = require("@bufbuild/protoplugin"); | ||
const { | ||
protocGenConnectQuery, | ||
} = require('../dist/cjs/src/protoc-gen-connect-query-plugin.js'); | ||
} = require("../dist/cjs/src/protoc-gen-connect-query-plugin.js"); | ||
|
||
runNodeJs(protocGenConnectQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters