-
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
Why is client nullable in MutationResult type? #6374
Comments
I have another related question:
The data passed in the update function can be null or undefined. Why is that? |
@fromi Default graphql behaviour is |
@jeffreyffs Here we are inside an "update" function of a mutation: why can it be undefined? If we run the function, it mean that it has returned, so the data has loaded. |
You've forced the type of your I could see an argument for having it not be |
I am not exactly forcing the type, I am specifying it. Otherwise data has "any" type, which indeed cause no warning or compilation error of any kind, which is not what I want. |
Let us know if this is still a concern with |
There is no change in the latest version of Apollo: |
Happy to look at a PR that addresses this @fromi - thanks! |
@hwillson can you share what the rationale is behind the |
I think this is a bug - I don't see a case where mutationResult in useMutations' hook can be undefined and clearly apollo authors did not provide any such case. It looks like someone was lazy writing the types definition and just added null | undefined without much thinking |
This has been fixed since |
That PR only fixes the |
As pointed out above, I think this issue should still be open unless a reason is given why Types as pasted from my export interface FetchResult<TData = Record<string, any>, TContext = Record<string, any>, TExtensions = Record<string, any>> extends ExecutionResult<TData, TExtensions> {
// Here
data?: TData | null | undefined;
extensions?: TExtensions;
context?: TContext;
} |
I found this in the documentation, which gives a reason for undefined-ness of data, but that could be fixed with some stricter typing: https://www.apollographql.com/docs/react/api/react/hooks/#data |
The problem still exists and is very bothersome. |
Using Typescript, I notice that when I use
useQuery
, I collect a non nullable 'client' property.However, with
useMutation
, it is nullable.This does not seems right: to get a mutation result, one must have an Apollo Client.
Is this intended or is it a mistake in the typing?
The text was updated successfully, but these errors were encountered: