-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable strict mode in tsconfig and fix type errors #11200
Changes from 1 commit
aca904f
0da3d3d
78ccf61
69d528a
e503cbb
0fe49a0
e34d084
962bd47
36129f8
cea054e
bed3439
b568689
6498326
b8c6eb6
c3a761d
9eb5e3e
0966cc9
a101977
55a6351
f909921
e1e2fbb
0426c84
be151b0
c83b042
4aa485b
1e7c5c6
c080309
0b2cf25
9303630
5e3fb70
04dcc0d
2cb5c83
94b07f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,11 @@ import type { | |
ErrorPolicy, | ||
MutationFetchPolicy, | ||
} from "./watchQueryOptions.js"; | ||
import { ObservableQuery, logMissingFieldErrors } from "./ObservableQuery.js"; | ||
import { | ||
ObservableQuery, | ||
ensureResult, | ||
logMissingFieldErrors, | ||
} from "./ObservableQuery.js"; | ||
import { NetworkStatus, isNetworkRequestInFlight } from "./networkStatus.js"; | ||
import type { | ||
ApolloQueryResult, | ||
|
@@ -479,7 +483,7 @@ export class QueryManager<TStore> { | |
const results: any[] = []; | ||
|
||
this.refetchQueries({ | ||
updateCache: (cache: TCache) => { | ||
updateCache: (cache) => { | ||
if (!skipCache) { | ||
cacheWrites.forEach((write) => cache.write(write)); | ||
} | ||
|
@@ -526,7 +530,7 @@ export class QueryManager<TStore> { | |
// either a SingleExecutionResult or the final ExecutionPatchResult, | ||
// call the update function. | ||
if (isFinalResult) { | ||
update(cache, result, { | ||
update(cache as TCache, result, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
context: mutation.context, | ||
variables: mutation.variables, | ||
}); | ||
|
@@ -616,8 +620,11 @@ export class QueryManager<TStore> { | |
options: WatchQueryOptions<TVars, TData>, | ||
networkStatus?: NetworkStatus | ||
): Promise<ApolloQueryResult<TData>> { | ||
return this.fetchConcastWithInfo(queryId, options, networkStatus).concast | ||
.promise; | ||
return this.fetchConcastWithInfo( | ||
queryId, | ||
options, | ||
networkStatus | ||
).concast.promise.then(ensureResult); | ||
} | ||
|
||
public getQueryStore() { | ||
|
@@ -1301,7 +1308,7 @@ export class QueryManager<TStore> { | |
normalized.variables, | ||
normalized.context | ||
) | ||
.then(fromVariables) | ||
.then(fromVariables as (Variables: any) => SourcesAndInfo<TData>) | ||
.then((sourcesWithInfo) => sourcesWithInfo.sources) | ||
); | ||
// there is just no way we can synchronously get the *right* value here, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import type { RequestHandler } from "../core/index.js"; | ||
import { ApolloLink } from "../core/index.js"; | ||
import type { HttpOptions } from "./selectHttpOptionsAndBody.js"; | ||
import { createHttpLink } from "./createHttpLink.js"; | ||
|
||
export class HttpLink extends ApolloLink { | ||
public requester: RequestHandler; | ||
constructor(public options: HttpOptions = {}) { | ||
Comment on lines
5
to
6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
super(createHttpLink(options).request); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ export function withMutation< | |
|
||
return ( | ||
<Mutation ignoreResults {...opts} mutation={document}> | ||
{/* @ts-expect-error */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not gonna fix types in the old HOCs... |
||
{( | ||
mutate: MutationFunction<TData, TGraphQLVariables>, | ||
{ data, ...r }: MutationResult<TData> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import type { | |
import type { | ||
ApolloCache, | ||
DefaultContext, | ||
MutationOptions, | ||
OperationVariables, | ||
} from "../../core/index.js"; | ||
import { mergeOptions } from "../../utilities/index.js"; | ||
|
@@ -87,10 +88,10 @@ export function useMutation< | |
} | ||
|
||
const mutationId = ++ref.current.mutationId; | ||
const clientOptions = mergeOptions(baseOptions, executeOptions as any); | ||
const clientOptions = mergeOptions(baseOptions, executeOptions); | ||
|
||
return client | ||
.mutate(clientOptions) | ||
.mutate(clientOptions as MutationOptions<TData, OperationVariables>) | ||
.then((response) => { | ||
const { data, errors } = response; | ||
const error = | ||
|
@@ -102,7 +103,10 @@ export function useMutation< | |
executeOptions.onError || ref.current.options?.onError; | ||
|
||
if (error && onError) { | ||
onError(error, clientOptions); | ||
onError( | ||
error, | ||
clientOptions as MutationOptions<TData, OperationVariables> | ||
); | ||
Comment on lines
+106
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to look closer into these, but for now I'm just casting them around.. |
||
} | ||
|
||
if ( | ||
|
@@ -126,7 +130,10 @@ export function useMutation< | |
executeOptions.onCompleted || ref.current.options?.onCompleted; | ||
|
||
if (!error) { | ||
onCompleted?.(response.data!, clientOptions); | ||
onCompleted?.( | ||
response.data!, | ||
clientOptions as MutationOptions<TData, OperationVariables> | ||
); | ||
} | ||
|
||
return response; | ||
|
@@ -150,7 +157,10 @@ export function useMutation< | |
executeOptions.onError || ref.current.options?.onError; | ||
|
||
if (onError) { | ||
onError(error, clientOptions); | ||
onError( | ||
error, | ||
clientOptions as MutationOptions<TData, OperationVariables> | ||
); | ||
|
||
// TODO(brian): why are we returning this here??? | ||
return { data: void 0, errors: error }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are generally very inconsistent with the
extends OperationVariables
onTVariables
, and I have to say I'm not too happy withOperationVariables
, as it works withtype
-declared types, but not with interfaces (as those don't have an implicit index signature).We might want to look into that - but not in this PR.