Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lifeomic/one-query into rename-qu…
Browse files Browse the repository at this point in the history
…eries
  • Loading branch information
swain committed Oct 21, 2022
2 parents 905330a + 945ce69 commit 669cca4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn add @lifeomic/one-query

## Setup

1. Define the input + output types for your API endpoints. Use a single type to define every endpoint.
1. Define the input + output types for your API endpoints. Use a single type to define the entire set of endpoints.

```typescript
// endpoints.ts
Expand Down Expand Up @@ -156,7 +156,9 @@ Well-typed hooks should first be created using the `createAPIHooks` helper.
```typescript
import { createAPIHooks } from '@lifeomic/one-query';

const hooks = createAPIHooks<APIEndpoints>({ // <-- Specify your custom endpointstype here
// Passing the explicit generic parameter is important.
// Provide your custom endpoints type as the parameter.
const hooks = createAPIHooks<APIEndpoints>({
// Provide a unique name for this API. This value is only used internally,
// to ensure that cached queries are scoped only to this set of created
// hooks.
Expand Down Expand Up @@ -190,6 +192,8 @@ const query = useAPIQuery(
The return value of this hook is identical to the behavior of the `react-query` `useQuery` hook's return value.
```typescript
const query = useQuery('GET /messages', { filter: 'some-filter' });

query.data; // Message[] | undefined

if (query.isLoading) {
Expand All @@ -206,15 +210,13 @@ Queries are cached using a combination of `route name + payload`. So, in the exa
### `useAPIMutation`
Type-safe wrapper around `useQuery` from `react-query`.
```typescript
const mutation = useAPIQuery('PUT /messages/:id');
```
Type-safe wrapper around `useMutation` from `react-query`.
The return value of this hook is identical to the behavior of the `react-query` `useMutation` hook's return value. The `mutate` and `mutateAsync` values are typed correctly using the endpoint definition
```tsx
const mutation = useMutation('PUT /messages/:id');

return (
<button
onClick={() => {
Expand All @@ -233,6 +235,8 @@ return (
A helper for combining multiple parallel queries into a single `react-query`-like hook.
Queries performed using this hook are cached independently, just as if they had been performed individually using `useAPIQuery`.
```typescript
const query = useCombinedAPIQueries(
['GET /messages', { filter: 'some-filter' }],
Expand All @@ -249,6 +253,8 @@ if (query.isLoading) {
return;
}

// Now, we know that all queries are complete.

query.data; // [Message[], Message]

const [list, message] = query.data;
Expand All @@ -257,8 +263,6 @@ list; // Message[]
message; // Message
```
Queries performed using this hook are cached independently, just as if they had been performed individually using `useAPIQuery`.
#### `isFetching`
Indicates whether _at least one_ query is in the "fetching" state.
Expand Down Expand Up @@ -289,7 +293,7 @@ const query = useCombinedAPIQueries(
query.refetchAll();

// Is equivalent to:
for (const individualQuery of queries) {
for (const individualQuery of query.queries) {
void individualQuery.refetch();
}
```
Expand Down
16 changes: 16 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
branches: ['master'],
plugins: [
['@semantic-release/commit-analyzer', { preset: 'conventionalcommits' }],
['@semantic-release/npm', { pkgRoot: './dist' }],
[
'@semantic-release/github',
{
// Setting this to false disables the default behavior
// of opening a GitHub issue when a release fails.
// We have other methods of tracking these failures.
failComment: false,
},
],
],
};

0 comments on commit 669cca4

Please sign in to comment.