Conversation
✅ Deploy Preview for kitbag-query ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
71348d1 to
069bef8
Compare
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
docs/core-concepts/queries.md
Outdated
| | `errored` | `boolean` | Whether the query has encountered an error. | | ||
| | `executed` | `boolean` | Whether the query has been executed at least once. | | ||
| | `executing` | `boolean` | Whether the query is currently executing. | | ||
| | `execute` | `(...args) => Promise<T>` | Function to manually trigger the query. Accepts arguments to use when calling your function, will override arguments supplied when creating the query. | |
There was a problem hiding this comment.
I don't think this is correct. execute doesn't accept any arguments. Its just a way to trigger the query. Specifically if immediate: false is used.
There was a problem hiding this comment.
look like you're right. not sure how I got this mixed up. Not sure it's specifically for immediate: false though. Since execute is on regular query not only useQuery and immediate: boolean is only an option on useQuery
| ### Execute | ||
|
|
||
| The query includes `execute`, which can be called at any point to force the function to be called again. Execute optionally takes the arguments that match the arguments on the function. If supplied, these arguments will override whatever arguments were supplied when creating the query. | ||
|
|
||
| ```ts | ||
| const messageFeedQuery = query(getMessages, () => null, { immediate: false }) | ||
|
|
||
| const newMessages = await messageFeedQuery.execute(Date.now()) | ||
| ``` |
There was a problem hiding this comment.
Unless I'm mistake about execute not accepting arguments, this section is incorrect.
| ### Awaiting Queries | ||
|
|
||
| When creating a query, you have the option of using `await` which changes the `data` attribute from being `T | undefined` to `T` since we can be sure that your function has executed. | ||
|
|
||
| ```ts | ||
| const regularQuery = await query(getMessages, () => Date.now()) | ||
| // ^? data: Message[] | undefined | ||
| const awaitedQuery = await query(getMessages, () => Date.now()) | ||
| // ^? data: Message[] | ||
| ``` |
There was a problem hiding this comment.
Probably good to mention that when using async await with queries any errors will be thrown
docs/core-concepts/queries.md
Outdated
| ```ts | ||
| const selectedUserId = ref<string | undefined>() | ||
|
|
||
| const userQuery = useQuery(fetchUser, () => selectedUserId.value ? [selectedUserId.value] : null) |
There was a problem hiding this comment.
Chance to encourage more readable code with less turneries.
| const userQuery = useQuery(fetchUser, () => selectedUserId.value ? [selectedUserId.value] : null) | |
| const userQuery = useQuery(fetchUser, () => { | |
| if(!selectedUserId.value) { | |
| return null | |
| } | |
| return [selectedUserId.value] | |
| }) |
docs/core-concepts/queries.md
Outdated
| ### Delayed execution | ||
|
|
||
| Queries will always wait if the parameters aren't ready, but you can also setup a query to always delay execution of the function until you either call `execute()` on the query, or change the reactive parameters argument. |
There was a problem hiding this comment.
This needs an example, I think you're talking about immediate: false?
There was a problem hiding this comment.
agreed this was unclear. Should be better with next commit
docs/core-concepts/queries.md
Outdated
| // defineQuery - consistent configuration | ||
| const { useQuery: useUserQuery } = defineQuery(fetchUser, { staleTime: 60000 }) | ||
| const user1 = useUserQuery([1]) // Uses predefined staleTime | ||
| const user2 = useUserQuery([2]) // Uses predefined staleTime |
There was a problem hiding this comment.
I think this is a bit misleading. You can still customize the options when you call the query. defineQuery does two things
- pre defines the action
- pre defines default options.
But you can override the options when you call the query.
There was a problem hiding this comment.
tbh this was OG Claude code that I forgot to revisit 😅
docs/api/index.md
Outdated
|
|
||
| **Parameters:** | ||
| - `key`: Unique identifier for the query | ||
| - `fetcher`: Async function that fetches the data |
There was a problem hiding this comment.
In code we call this the "action". I don't feel strongly about the name. But I'd use action for consistency.
There was a problem hiding this comment.
I'll comment this out and revisit in future PR
docs/api/index.md
Outdated
| function query<TParams extends any[], TData>( | ||
| key: string, | ||
| fetcher: (...params: TParams) => Promise<TData>, | ||
| options?: QueryOptions | ||
| ): QueryFunction<TParams, TData> |
There was a problem hiding this comment.
I'll comment this out and revisit in future PR
docs/api/index.md
Outdated
| // Caching options | ||
| defaultStaleTime?: number | ||
| defaultCacheTime?: number | ||
|
|
||
| // Retry options | ||
| defaultRetryCount?: number | ||
| defaultRetryDelay?: number | ((attempt: number) => number) | ||
|
|
||
| // Other options... |
There was a problem hiding this comment.
I'll comment this out and revisit in future PR
docs/api/index.md
Outdated
| ## Error Types | ||
|
|
||
| ### QueryError | ||
|
|
||
| Base error class for query-related errors. | ||
|
|
||
| ```ts | ||
| class QueryError extends Error { | ||
| readonly name = 'QueryError' | ||
| // ... error details | ||
| } | ||
| ``` | ||
|
|
||
| For more detailed examples and usage patterns, see the [Core Concepts](/core-concepts/query-client) section. No newline at end of file |
There was a problem hiding this comment.
I'll comment this out and revisit in future PR
| const response = await fetch('/api/users', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify(userData) | ||
| }) | ||
|
|
||
| if (!response.ok) throw new Error('Failed to create user') | ||
| return response.json() | ||
| }) |
There was a problem hiding this comment.
it's commented out because I didn't get this far
docs/core-concepts/queries.md
Outdated
| }) | ||
| ``` | ||
|
|
||
| You can also setup a query NOT to execute immediately. These queries wait until you either call `execute()`, or change the reactive parameters argument. |
There was a problem hiding this comment.
Does changing the parameters execute a query that has immediate: false? Feels like it shouldn't.
There was a problem hiding this comment.
good catch, I looked again and confirmed in query-preview that you MUST call execute to re-enable a query when immediate is false
added vitepress documentation, readme, as well as some release prep work
most of the actual documentation is authored heavily by Claude, so it'll need some close inspection for accuracy.
Netlify is not yet configured on this project yet, so here's the manual deploy of this branch
https://kitbag-query.netlify.app