mirror of
https://github.com/vuejs/apollo.git
synced 2025-12-08 18:02:09 +00:00
feat(ts): update types to account for changes in TypeScript 4.8 (#1454)
Co-authored-by: Guillaume Chau <guillaume.b.chau@gmail.com>
This commit is contained in:
parent
2f4c6c358d
commit
b2f773c6f7
@ -13,7 +13,7 @@
|
||||
"api": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.6.9",
|
||||
"@apollo/client": "^3.7.7",
|
||||
"@vue/apollo-composable": "workspace:*",
|
||||
"@vue/apollo-util": "workspace:*",
|
||||
"apollo-server-express": "^2.25.4",
|
||||
|
||||
@ -27,7 +27,7 @@ module.exports = {
|
||||
throw new Error('An error')
|
||||
},
|
||||
loadNumber: () => new Promise((resolve) => {
|
||||
setTimeout(() => resolve(42), 100)
|
||||
setTimeout(() => resolve(42), 500)
|
||||
}),
|
||||
items: () => [
|
||||
{
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
"api": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.6.9",
|
||||
"@apollo/client": "^3.7.7",
|
||||
"@vue/apollo-components": "workspace:*",
|
||||
"@vue/apollo-option": "workspace:*",
|
||||
"apollo-server-express": "^2.25.4",
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
"vue": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apollo/client": "^3.6.9",
|
||||
"@apollo/client": "^3.7.7",
|
||||
"@babel/core": "^7.18.5",
|
||||
"@babel/plugin-proposal-class-properties": "^7.17.12",
|
||||
"@babel/plugin-transform-for-of": "^7.18.1",
|
||||
|
||||
@ -61,7 +61,7 @@
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apollo/client": "^3.6.9",
|
||||
"@apollo/client": "^3.7.7",
|
||||
"@types/throttle-debounce": "^2.1.0",
|
||||
"graphql": "^15.8.0",
|
||||
"graphql-tag": "^2.12.6",
|
||||
|
||||
@ -4,13 +4,12 @@ import { useQueryImpl, DocumentParameter, VariablesParameter, OptionsParameter,
|
||||
|
||||
export function useLazyQuery<
|
||||
TResult = any,
|
||||
TVariables = any,
|
||||
TVariables extends Record<string, unknown> = any,
|
||||
> (
|
||||
document: DocumentParameter<TResult, TVariables>,
|
||||
variables?: VariablesParameter<TVariables>,
|
||||
options?: OptionsParameter<TResult, TVariables>,
|
||||
) {
|
||||
// @ts-expect-error apollo-client types issue with TVariables
|
||||
const query = useQueryImpl<TResult, TVariables>(document, variables, options, true)
|
||||
|
||||
function load (
|
||||
|
||||
@ -37,8 +37,7 @@ import type { CurrentInstance } from './util/types'
|
||||
export interface UseQueryOptions<
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
TResult = any,
|
||||
TVariables = OperationVariables
|
||||
// @ts-expect-error apollo-client types issue with TVariables
|
||||
TVariables extends OperationVariables = OperationVariables
|
||||
> extends Omit<WatchQueryOptions<TVariables>, 'query' | 'variables'> {
|
||||
clientId?: string
|
||||
enabled?: boolean
|
||||
@ -55,10 +54,10 @@ interface SubscribeToMoreItem {
|
||||
// Parameters
|
||||
export type DocumentParameter<TResult, TVariables = undefined> = DocumentNode | Ref<DocumentNode> | ReactiveFunction<DocumentNode> | TypedDocumentNode<TResult, TVariables> | Ref<TypedDocumentNode<TResult, TVariables>> | ReactiveFunction<TypedDocumentNode<TResult, TVariables>>
|
||||
export type VariablesParameter<TVariables> = TVariables | Ref<TVariables> | ReactiveFunction<TVariables>
|
||||
export type OptionsParameter<TResult, TVariables> = UseQueryOptions<TResult, TVariables> | Ref<UseQueryOptions<TResult, TVariables>> | ReactiveFunction<UseQueryOptions<TResult, TVariables>>
|
||||
export type OptionsParameter<TResult, TVariables extends OperationVariables> = UseQueryOptions<TResult, TVariables> | Ref<UseQueryOptions<TResult, TVariables>> | ReactiveFunction<UseQueryOptions<TResult, TVariables>>
|
||||
|
||||
// Return
|
||||
export interface UseQueryReturn<TResult, TVariables> {
|
||||
export interface UseQueryReturn<TResult, TVariables extends OperationVariables> {
|
||||
result: Ref<TResult | undefined>
|
||||
loading: Ref<boolean>
|
||||
networkStatus: Ref<number | undefined>
|
||||
@ -70,7 +69,6 @@ export interface UseQueryReturn<TResult, TVariables> {
|
||||
document: Ref<DocumentNode>
|
||||
variables: Ref<TVariables | undefined>
|
||||
options: UseQueryOptions<TResult, TVariables> | Ref<UseQueryOptions<TResult, TVariables>>
|
||||
// @ts-expect-error apollo-client types issue with TVariables
|
||||
query: Ref<ObservableQuery<TResult, TVariables> | null | undefined>
|
||||
refetch: (variables?: TVariables) => Promise<ApolloQueryResult<TResult>> | undefined
|
||||
fetchMore: (options: FetchMoreQueryOptions<TVariables, TResult> & FetchMoreOptions<TResult, TVariables>) => Promise<ApolloQueryResult<TResult>> | undefined
|
||||
@ -88,7 +86,7 @@ export interface UseQueryReturn<TResult, TVariables> {
|
||||
* */
|
||||
export function useQuery<TResult = any> (
|
||||
document: DocumentParameter<TResult, undefined>
|
||||
): UseQueryReturn<TResult, undefined>
|
||||
): UseQueryReturn<TResult, Record<string, never>>
|
||||
|
||||
/**
|
||||
* Use a query that has optional variables but not options
|
||||
@ -111,8 +109,8 @@ export function useQuery<TResult = any, TVariables extends OperationVariables =
|
||||
export function useQuery<TResult = any> (
|
||||
document: DocumentParameter<TResult, undefined>,
|
||||
variables: undefined | null,
|
||||
options: OptionsParameter<TResult, null>,
|
||||
): UseQueryReturn<TResult, null>
|
||||
options: OptionsParameter<TResult, Record<string, never>>,
|
||||
): UseQueryReturn<TResult, Record<string, never>>
|
||||
|
||||
/**
|
||||
* Use a query that requires variables and options.
|
||||
@ -220,7 +218,7 @@ export function useQueryImpl<
|
||||
|
||||
query.value = client.watchQuery<TResult, TVariables>({
|
||||
query: currentDocument,
|
||||
variables: currentVariables,
|
||||
variables: currentVariables ?? {} as TVariables,
|
||||
...currentOptions.value,
|
||||
...(isServer && currentOptions.value?.fetchPolicy !== 'no-cache')
|
||||
? {
|
||||
|
||||
@ -105,7 +105,7 @@ export function useSubscription<TResult = any, TVariables extends OperationVaria
|
||||
|
||||
export function useSubscription <
|
||||
TResult,
|
||||
TVariables
|
||||
TVariables extends Record<string, unknown>
|
||||
> (
|
||||
document: DocumentParameter<TResult, TVariables>,
|
||||
variables: VariablesParameter<TVariables> | undefined = undefined,
|
||||
@ -140,7 +140,6 @@ export function useSubscription <
|
||||
|
||||
const client = resolveClient(currentOptions.value?.clientId)
|
||||
|
||||
// @ts-expect-error apollo-client types issue with TVariables
|
||||
subscription.value = client.subscribe<TResult, TVariables>({
|
||||
query: currentDocument,
|
||||
variables: currentVariables,
|
||||
|
||||
@ -20,7 +20,7 @@ import { assertExactType } from './assertions'
|
||||
useQueryNoTypesResult.type.is.any
|
||||
|
||||
const useQueryNoTypesVariables = useQueryNoTypes.variables.value
|
||||
assertExactType<typeof useQueryNoTypesVariables, undefined>(useQueryNoTypesVariables)
|
||||
assertExactType<typeof useQueryNoTypesVariables, Record<string, never> | undefined>(useQueryNoTypesVariables)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@ -35,7 +35,7 @@ import { assertExactType } from './assertions'
|
||||
assertExactType<typeof useQueryOnlyQueryTypeResult, ExampleQuery | null | undefined>(useQueryOnlyQueryTypeResult)
|
||||
|
||||
const useQueryOnlyQueryTypeVariables = useQueryOnlyQueryType.variables.value
|
||||
assertExactType<typeof useQueryOnlyQueryTypeVariables, undefined>(useQueryOnlyQueryTypeVariables)
|
||||
assertExactType<typeof useQueryOnlyQueryTypeVariables, Record<string, never> | undefined>(useQueryOnlyQueryTypeVariables)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@ -111,7 +111,7 @@ import { assertExactType } from './assertions'
|
||||
|
||||
const useQueryOnlyQueryTypeNoVarsWithOptionsVariables =
|
||||
useQueryOnlyQueryTypeNoVarsWithOptions.variables.value
|
||||
assertExactType<typeof useQueryOnlyQueryTypeNoVarsWithOptionsVariables, null | undefined>(
|
||||
assertExactType<typeof useQueryOnlyQueryTypeNoVarsWithOptionsVariables, Record<string, never> | undefined>(
|
||||
useQueryOnlyQueryTypeNoVarsWithOptionsVariables,
|
||||
)
|
||||
}
|
||||
@ -132,7 +132,7 @@ import { assertExactType } from './assertions'
|
||||
|
||||
const useQueryOnlyQueryTypeNoVarsWithOptionsVariables =
|
||||
useQueryOnlyQueryTypeNoVarsWithOptions.variables.value
|
||||
assertExactType<typeof useQueryOnlyQueryTypeNoVarsWithOptionsVariables, null | undefined>(
|
||||
assertExactType<typeof useQueryOnlyQueryTypeNoVarsWithOptionsVariables, Record<string, never> | undefined>(
|
||||
useQueryOnlyQueryTypeNoVarsWithOptionsVariables,
|
||||
)
|
||||
}
|
||||
@ -148,7 +148,9 @@ import { assertExactType } from './assertions'
|
||||
{ id: '4E79Lq' },
|
||||
{
|
||||
clientId: 'any',
|
||||
context: { foo: 'any' },
|
||||
context: {
|
||||
string: 'any',
|
||||
},
|
||||
debounce: 500,
|
||||
enabled: true,
|
||||
errorPolicy: 'all',
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
"throttle-debounce": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apollo/client": "^3.6.9",
|
||||
"@apollo/client": "^3.7.7",
|
||||
"@babel/core": "^7.18.5",
|
||||
"@babel/plugin-proposal-class-properties": "^7.17.12",
|
||||
"@babel/plugin-transform-for-of": "^7.18.1",
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
"serialize-javascript": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apollo/client": "^3.6.9",
|
||||
"@apollo/client": "^3.7.7",
|
||||
"@types/serialize-javascript": "^5.0.2",
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
"prepublishOnly": "pnpm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apollo/client": "^3.6.9",
|
||||
"@apollo/client": "^3.7.7",
|
||||
"graphql": "^15.8.0",
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
|
||||
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
@ -72,7 +72,7 @@ importers:
|
||||
packages/test-e2e:
|
||||
dependencies:
|
||||
'@apollo/client':
|
||||
specifier: ^3.6.9
|
||||
specifier: ^3.7.7
|
||||
version: 3.7.9(graphql@15.8.0)(subscriptions-transport-ws@0.9.19)
|
||||
'@vue/apollo-components':
|
||||
specifier: workspace:*
|
||||
@ -172,7 +172,7 @@ importers:
|
||||
packages/test-e2e-composable-vue3:
|
||||
dependencies:
|
||||
'@apollo/client':
|
||||
specifier: ^3.6.9
|
||||
specifier: ^3.7.7
|
||||
version: 3.7.9(graphql@15.8.0)(subscriptions-transport-ws@0.9.19)
|
||||
'@vue/apollo-composable':
|
||||
specifier: workspace:*
|
||||
@ -255,7 +255,7 @@ importers:
|
||||
version: link:../vue-apollo-option
|
||||
devDependencies:
|
||||
'@apollo/client':
|
||||
specifier: ^3.6.9
|
||||
specifier: ^3.7.7
|
||||
version: 3.7.9(graphql@15.8.0)(subscriptions-transport-ws@0.9.19)
|
||||
'@babel/core':
|
||||
specifier: ^7.18.5
|
||||
@ -337,7 +337,7 @@ importers:
|
||||
version: 0.13.11(@vue/composition-api@1.0.0)(vue@3.2.47)
|
||||
devDependencies:
|
||||
'@apollo/client':
|
||||
specifier: ^3.6.9
|
||||
specifier: ^3.7.7
|
||||
version: 3.7.9(graphql@15.8.0)(subscriptions-transport-ws@0.9.19)
|
||||
'@types/throttle-debounce':
|
||||
specifier: ^2.1.0
|
||||
@ -368,7 +368,7 @@ importers:
|
||||
version: 3.0.1
|
||||
devDependencies:
|
||||
'@apollo/client':
|
||||
specifier: ^3.6.9
|
||||
specifier: ^3.7.7
|
||||
version: 3.7.9(graphql@15.8.0)(subscriptions-transport-ws@0.9.19)
|
||||
'@babel/core':
|
||||
specifier: ^7.18.5
|
||||
@ -447,7 +447,7 @@ importers:
|
||||
version: 6.0.1
|
||||
devDependencies:
|
||||
'@apollo/client':
|
||||
specifier: ^3.6.9
|
||||
specifier: ^3.7.7
|
||||
version: 3.7.9(graphql@15.8.0)(subscriptions-transport-ws@0.9.19)
|
||||
'@types/serialize-javascript':
|
||||
specifier: ^5.0.2
|
||||
@ -459,7 +459,7 @@ importers:
|
||||
packages/vue-apollo-util:
|
||||
devDependencies:
|
||||
'@apollo/client':
|
||||
specifier: ^3.6.9
|
||||
specifier: ^3.7.7
|
||||
version: 3.7.9(graphql@15.8.0)(subscriptions-transport-ws@0.9.19)
|
||||
graphql:
|
||||
specifier: ^15
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user