connect-query-es

TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers.

APACHE-2.0 License

Downloads
218.1K
Stars
186

Bot releases are visible (Hide)

connect-query-es - v1.3.1 Latest Release

Published by paul-sachs 8 months ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v1.3.0...v1.3.1

connect-query-es - v1.3.0

Published by paul-sachs 8 months ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v1.2.0...v1.3.0

connect-query-es - v1.2.0

Published by paul-sachs 8 months ago

What's Changed

Changes to infinite query keys

With https://github.com/connectrpc/connect-query-es/pull/334, we're fixing a bug where the cache of a regular query collides with the cache of an infinite query, which can lead to type mismatches and unexpected failures if you use the same RPC with an infinite query and a regular query.
We are now using a separate query key for infinite queries to solve the issue (we append "infinite" to the key), but this change can potentially affect you:

If you tried to invalidate some infinite queries like queryClient.invalidateQueries({ queryKey: createConnectQueryKey(...), exact: true }), this now only invalidates queries initialized with useQuery. To invalidate infinite queries, you can either set exact to false, or use createConnectInfiniteQueryKey() instead. Also note that this change not only affects invalidateQueries but any operations against the queryClient that interact with the cache using a key (eg, queryClient.setQueriesData, etc.)

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v1.1.3...v1.2.0

connect-query-es - v1.1.3

Published by paul-sachs 9 months ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v1.1.2...v1.1.3

connect-query-es - v1.1.2

Published by paul-sachs 10 months ago

connect-query-es - v1.1.1

Published by paul-sachs 10 months ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v1.1.0...v1.1.1

connect-query-es - v1.1.0

Published by paul-sachs 10 months ago

What's Changed

CJS output

By default, protoc-gen-connect-query (and all other plugins based on @bufbuild/protoplugin) generate ECMAScript import and export statements. For use cases where CommonJS is difficult to avoid, a new plugin option has been added named js_import_style which can be used to generate CommonJS require() calls.

Here is an example buf.gen.yaml:

version: v1
plugins:
  # You'll need @bufbuild/protoc-gen-es v1.6.0 or later
  - plugin: es
    out: src/gen
    opt: js_import_style=legacy_commonjs
  - plugin: protoc-gen-connect-query
    out: src/gen
    opt: js_import_style=legacy_commonjs

To view the full PR, see Added support for cjs output by @paul-sachs in https://github.com/connectrpc/connect-query-es/pull/303

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v1.0.0...v1.1.0

connect-query-es - v1.0.0

Published by paul-sachs 11 months ago

What's Changed

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

import { useQuery } from "@connectrpc/connect-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

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

import { getUserOrganization } from "@apigen/org/alpha/registry/v1alpha1/organization-OrganizationService_connectquery";
import { useQuery } from "@connectrpc/connect-query";

...

const getUserOrganizationQuery = useQuery(getUserOrganization, {
      userId: currentUser?.id,
      organizationId,
    },
    {
      useErrorBoundary: false,
      enabled: currentUser !== null
    }
});

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v0.6.0...v1.0.0

connect-query-es - v0.6.0

Published by paul-sachs 12 months ago

What's Changed

Update to react-query@5

This update contains some breaking changes including, but not limited to:

  • Removed onError passed to useQuery, this aligns with the removed event handlers in @tanstack/query
  • useInfiniteQuery now requires the initial page param to be defined in the input because initialPageParam is required

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v0.5.3...v0.6.0

connect-query-es - v0.5.3

Published by paul-sachs about 1 year ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v0.5.2...v0.5.3

connect-query-es - v0.5.2

Published by paul-sachs about 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v0.5.1...v0.5.2

connect-query-es - v0.5.1

Published by paul-sachs about 1 year ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v0.4.4...v0.5.1

Summary of breaking changes

Changes in @connectrpc/connect-query

Breaking changes

  • Removed UnaryHooks type and replaced with UnaryFunctionsWithHooks
  • Updated createUnaryHooks to only return the hooks and not other functions

New functions

createUnaryFunctions

Introduced createUnaryFunctions which can be used with the new createUnaryHooks to do the same thing as the old createUnaryHooks. The reasoning behind this change is to prep the core library, connect-query, to be able to used separately from React itself and this is just the first step in that direction.

Changes in code generated by protoc-gen-connect-query and protoc-gen-connect-query-react

New functions

Each service method now generates two new functions associated to the method:

method.createUseInfiniteQueryOptions

This method creates options that will pass to useInfiniteQuery. It is identical to method.useInfiniteQuery except it needs to be passed a transport directly.

createUseMutationOptions

This method creates options that will pass to useMutation. It is identical to method.useMutation except it needs to be passed a transport directly.

We added these methods to better future-proof the code for incoming changes to React (React Server Components, etc).

Migration

  • Replace any usages of the type UnaryHooks with UnaryFunctionsWithHooks
  • Find any usages of createUnaryHooks and use a combination of createUnaryHooks and createUnaryFunctions

Before

const say = createUnaryHooks(ExampleService);

After

const say = {
  ...createUnaryHooks(ExampleService),
  ...createUnaryFunctions(ExampleService),
}
connect-query-es - v0.4.4

Published by paul-sachs about 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v0.4.3...v0.4.4

connect-query-es - v0.4.3

Published by paul-sachs about 1 year ago

What's Changed

Testing simplification

Exported serviced type allows you to directly use service with createRouterTransport from @connectrpc/connect with the exported service:

import { createRouterTransport } from "@connectrpc/connect";
import { ElizaService } from "./gen/eliza-ElizaService_connectquery";

...

const transport = createRouterTransport(({ service }) => {
  service(ElizaService, {
    say: () => ({
      sentence: "Hello, world!",
    }),
  });
});

For more details, see example test here.

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v0.4.2...v0.4.3

connect-query-es - v0.4.2

Published by paul-sachs about 1 year ago

What's Changed

To keep Connect well-maintained and responsive to its users' needs over the long term, we're preparing to donate it to a foundation. (More details on that soon!) To cleanly separate Connect from Buf's other code, we're moving development to the connectrpc GitHub organization and to the connectrpc organization on npmjs.com.

This is the first release that publishes packages with the new @connectrpc scope. To make the switch seamless, we are introducing a small tool that updates all references in your project automatically, @connectrpc/connect-migrate.

The switch is as simple as running a single command:

$ npx @connectrpc/connect-migrate@latest
Scanning... ✓
    1 package.json file
    1 lock file
    5 source files
Updating source files... 
  src/client.ts ✓
  src/server.ts ✓
  src/webclient.ts ✓
Updating packages... ✓
  package.json ✓
Updating lock file... 
  package-lock.json ✓
Old package New package
@bufbuild/connect v0.13.0 @connectrpc/connect v0.13.1
@bufbuild/connect-web v0.13.0 @connectrpc/connect-web v0.13.1
@bufbuild/connect-fastify v0.13.0 @connectrpc/connect-fastify v0.13.1
@bufbuild/connect-node v0.13.0 @connectrpc/connect-node v0.13.1
@bufbuild/connect-next v0.13.0 @connectrpc/connect-next v0.13.1
@bufbuild/connect-express v0.13.0 @connectrpc/connect-express v0.13.1
@bufbuild/protoc-gen-connect-es v0.13.0 @connectrpc/protoc-gen-connect-es v0.13.1
@bufbuild/connect-query v0.4.1 @connectrpc/connect-query v0.4.2
@bufbuild/protoc-gen-connect-query v0.4.1 @connectrpc/protoc-gen-connect-query v0.4.2
@bufbuild/protoc-gen-connect-query-react v0.4.1 @connectrpc/protoc-gen-connect-query-react v0.4.2

Full Changelog: https://github.com/connectrpc/connect-query-es/compare/v0.4.1...v0.4.2

connect-query-es - v0.4.1

Published by paul-sachs about 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/bufbuild/connect-query/compare/v0.4.0...v0.4.1