Skip to content

Commit

Permalink
Merge branch 'main' into types/query-core/OmitKeyof
Browse files Browse the repository at this point in the history
  • Loading branch information
manudeli committed May 2, 2024
2 parents a084d8e + 9ff2c2e commit c0bd580
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 55 deletions.
4 changes: 2 additions & 2 deletions examples/angular/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^17.3.3",
"@angular/platform-browser-dynamic": "^17.3.3",
"@angular/router": "^17.3.3",
"@tanstack/angular-query-experimental": "^5.32.1",
"@tanstack/angular-query-experimental": "^5.33.0",
"rxjs": "^7.8.1",
"tslib": "^2.6.2",
"zone.js": "^0.14.4"
Expand All @@ -26,7 +26,7 @@
"@angular-devkit/build-angular": "^17.3.3",
"@angular/cli": "^17.3.3",
"@angular/compiler-cli": "^17.3.3",
"@tanstack/angular-query-devtools-experimental": "^5.32.1",
"@tanstack/angular-query-devtools-experimental": "^5.33.0",
"typescript": "5.2.2"
}
}
4 changes: 2 additions & 2 deletions examples/angular/infinite-query-with-max-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^17.3.3",
"@angular/platform-browser-dynamic": "^17.3.3",
"@angular/router": "^17.3.3",
"@tanstack/angular-query-experimental": "^5.32.1",
"@tanstack/angular-query-experimental": "^5.33.0",
"rxjs": "^7.8.1",
"tslib": "^2.6.2",
"zone.js": "^0.14.4"
Expand All @@ -26,7 +26,7 @@
"@angular-devkit/build-angular": "^17.3.3",
"@angular/cli": "^17.3.3",
"@angular/compiler-cli": "^17.3.3",
"@tanstack/angular-query-devtools-experimental": "^5.32.1",
"@tanstack/angular-query-devtools-experimental": "^5.33.0",
"typescript": "5.2.2"
}
}
4 changes: 2 additions & 2 deletions examples/angular/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^17.3.3",
"@angular/platform-browser-dynamic": "^17.3.3",
"@angular/router": "^17.3.3",
"@tanstack/angular-query-experimental": "^5.32.1",
"@tanstack/angular-query-experimental": "^5.33.0",
"rxjs": "^7.8.1",
"tslib": "^2.6.2",
"zone.js": "^0.14.4"
Expand All @@ -26,7 +26,7 @@
"@angular-devkit/build-angular": "^17.3.3",
"@angular/cli": "^17.3.3",
"@angular/compiler-cli": "^17.3.3",
"@tanstack/angular-query-devtools-experimental": "^5.32.1",
"@tanstack/angular-query-devtools-experimental": "^5.33.0",
"typescript": "5.2.2"
}
}
4 changes: 2 additions & 2 deletions examples/angular/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^17.3.3",
"@angular/platform-browser-dynamic": "^17.3.3",
"@angular/router": "^17.3.3",
"@tanstack/angular-query-experimental": "^5.32.1",
"@tanstack/angular-query-experimental": "^5.33.0",
"rxjs": "^7.8.1",
"tslib": "^2.6.2",
"zone.js": "^0.14.4"
Expand All @@ -26,7 +26,7 @@
"@angular-devkit/build-angular": "^17.3.3",
"@angular/cli": "^17.3.3",
"@angular/compiler-cli": "^17.3.3",
"@tanstack/angular-query-devtools-experimental": "^5.32.1",
"@tanstack/angular-query-devtools-experimental": "^5.33.0",
"typescript": "5.2.2"
}
}
4 changes: 2 additions & 2 deletions examples/solid/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"@astrojs/tailwind": "^5.1.0",
"@astrojs/vercel": "^7.5.3",
"@astrojs/node": "^8.2.5",
"@tanstack/solid-query": "^5.32.1",
"@tanstack/solid-query-devtools": "^5.32.1",
"@tanstack/solid-query": "^5.33.1",
"@tanstack/solid-query-devtools": "^5.33.1",
"astro": "^4.6.1",
"solid-js": "^1.8.14",
"tailwindcss": "^3.4.1",
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/basic-graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "tsc"
},
"dependencies": {
"@tanstack/solid-query": "^5.32.1",
"@tanstack/solid-query-devtools": "^5.32.1",
"@tanstack/solid-query": "^5.33.1",
"@tanstack/solid-query-devtools": "^5.33.1",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"solid-js": "^1.8.14"
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/basic-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "tsc"
},
"dependencies": {
"@tanstack/solid-query": "^5.32.1",
"@tanstack/solid-query-devtools": "^5.32.1",
"@tanstack/solid-query": "^5.33.1",
"@tanstack/solid-query-devtools": "^5.33.1",
"solid-js": "^1.8.14"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/default-query-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "tsc"
},
"dependencies": {
"@tanstack/solid-query": "^5.32.1",
"@tanstack/solid-query-devtools": "^5.32.1",
"@tanstack/solid-query": "^5.33.1",
"@tanstack/solid-query-devtools": "^5.33.1",
"solid-js": "^1.8.14"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test:types": "tsc"
},
"dependencies": {
"@tanstack/solid-query": "^5.32.1",
"@tanstack/solid-query-devtools": "^5.32.1",
"@tanstack/solid-query": "^5.33.1",
"@tanstack/solid-query-devtools": "^5.33.1",
"solid-js": "^1.8.14"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/solid-start-streaming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"@solidjs/meta": "^0.29.2",
"@solidjs/router": "^0.13.2",
"@solidjs/start": "^1.0.0-rc.0",
"@tanstack/solid-query": "^5.32.1",
"@tanstack/solid-query-devtools": "^5.32.1",
"@tanstack/solid-query": "^5.33.1",
"@tanstack/solid-query-devtools": "^5.33.1",
"solid-js": "^1.8.14",
"vinxi": "^0.3.10"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-query-devtools-experimental/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/angular-query-devtools-experimental",
"version": "5.32.1",
"version": "5.33.0",
"description": "Developer tools to interact with and visualize the TanStack/angular-query cache",
"author": "Arnoud de Vries",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-query-experimental/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/angular-query-experimental",
"version": "5.32.1",
"version": "5.33.0",
"description": "Signals for managing, caching and syncing asynchronous and remote data in Angular",
"author": "Arnoud de Vries",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Component, computed, input, signal } from '@angular/core'
import {
Component,
Injectable,
computed,
inject,
input,
signal,
} from '@angular/core'
import { TestBed, fakeAsync, flush, tick } from '@angular/core/testing'
import { QueryClient } from '@tanstack/query-core'
import { describe, expect, vi } from 'vitest'
Expand Down Expand Up @@ -297,4 +304,46 @@ describe('injectQuery', () => {
'signal-input-required-test',
)
}))

test('should run options in injection context', fakeAsync(async () => {
@Injectable()
class FakeService {
getData(name: string) {
return Promise.resolve(name)
}
}

@Component({
selector: 'app-fake',
template: `{{ query.data() }}`,
standalone: true,
providers: [FakeService],
})
class FakeComponent {
name = signal<string>('test name')

query = injectQuery(() => {
const service = inject(FakeService)

return {
queryKey: ['fake', this.name()],
queryFn: () => {
return service.getData(this.name())
},
}
})
}

const fixture = TestBed.createComponent(FakeComponent)
flush()
fixture.detectChanges()

expect(fixture.componentInstance.query.data()).toEqual('test name')

fixture.componentInstance.name.set('test name 2')
fixture.detectChanges()
flush()

expect(fixture.componentInstance.query.data()).toEqual('test name 2')
}))
})
9 changes: 8 additions & 1 deletion packages/angular-query-experimental/src/inject-query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { QueryObserver } from '@tanstack/query-core'
import { runInInjectionContext } from '@angular/core'
import { assertInjector } from './util/assert-injector/assert-injector'
import { injectQueryClient } from './inject-query-client'
import { createBaseQuery } from './create-base-query'
Expand Down Expand Up @@ -54,8 +55,14 @@ export function injectQuery(
options: (client: QueryClient) => CreateQueryOptions,
injector?: Injector,
) {
const assertedInjector = assertInjector(injectQuery, injector)
return assertInjector(injectQuery, injector, () => {
const queryClient = injectQueryClient()
return createBaseQuery(options, QueryObserver, queryClient)
return createBaseQuery(
(client) =>
runInInjectionContext(assertedInjector, () => options(client)),
QueryObserver,
queryClient,
)
})
}
2 changes: 1 addition & 1 deletion packages/solid-query-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/solid-query-devtools",
"version": "5.32.1",
"version": "5.33.1",
"description": "Developer tools to interact with and visualize the TanStack/solid-query Query cache",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-query-persist-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/solid-query-persist-client",
"version": "5.32.1",
"version": "5.33.1",
"description": "Solid.js bindings to work with persisters in TanStack/solid-query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/solid-query",
"version": "5.32.1",
"version": "5.33.1",
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
9 changes: 8 additions & 1 deletion packages/solid-query/src/createQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ type CreateQueryOptionsForCreateQueries<
TQueryKey extends QueryKey = QueryKey,
> = OmitKeyof<
SolidQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
'placeholderData'
'placeholderData' | 'suspense'
> & {
placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>
/**
* @deprecated The `suspense` option has been deprecated in v5 and will be removed in the next major version.
* The `data` property on createQueries is a plain object and not a SolidJS Resource.
* It will not suspend when the data is loading.
* Setting `suspense` to `true` will be a no-op.
*/
suspense?: boolean
}

// Avoid TS depth-limit error in case of large array literal
Expand Down
35 changes: 28 additions & 7 deletions packages/solid-query/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ export interface CreateBaseQueryOptions<
TData = TQueryFnData,
TQueryData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
> extends QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
> extends OmitKeyof<
QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
'suspense'
> {
/**
* Only applicable while rendering queries on the server with streaming.
* Set `deferStream` to `true` to wait for the query to resolve on the server before flushing the stream.
* This can be useful to avoid sending a loading state to the client before the query has resolved.
* Defaults to `false`.
*/
deferStream?: boolean
/**
* @deprecated The `suspense` option has been deprecated in v5 and will be removed in the next major version.
* The `data` property on createQuery is a SolidJS resource and will automatically suspend when the data is loading.
* Setting `suspense` to `false` will be a no-op.
*/
suspense?: boolean
}

export interface SolidQueryOptions<
Expand Down Expand Up @@ -93,10 +102,22 @@ export interface SolidInfiniteQueryOptions<
TQueryKey,
TPageParam
>,
'queryKey'
'queryKey' | 'suspense'
> {
queryKey: TQueryKey
/**
* Only applicable while rendering queries on the server with streaming.
* Set `deferStream` to `true` to wait for the query to resolve on the server before flushing the stream.
* This can be useful to avoid sending a loading state to the client before the query has resolved.
* Defaults to `false`.
*/
deferStream?: boolean
/**
* @deprecated The `suspense` option has been deprecated in v5 and will be removed in the next major version.
* The `data` property on createInfiniteQuery is a SolidJS resource and will automatically suspend when the data is loading.
* Setting `suspense` to `false` will be a no-op.
*/
suspense?: boolean
}

export type CreateInfiniteQueryOptions<
Expand Down
Loading

0 comments on commit c0bd580

Please sign in to comment.