`mutate` function leaves `data` and `variables` un-typed.
See original GitHub issueIntended outcome:
apollo-client uses strong typing. This issue is specifically addressing mutate
’s variables
and data
.
Actual outcome:
The results of mutate
are untyped, as are the variables
in the options.
How to reproduce the issue:
While this issue covers multiple projects’ types, the problem is exposed by usage of apollo-client mutate
.
apollo-client.mutate
is virtually un-typed (e.g. data
and variables
in typescript). The types that need parameterized adjustments cross apollo-client
, apollo-link
, and graphql
projects. Specifically the data result and variables are unsealed/unchecked and need to be cast if the user wants to use them after fetching.
apollo-client
mutate
:
mutate<T>(options: MutationOptions<T>): Promise<FetchResult<T>>
apollo-link
FetchResult
:
export declare type FetchResult<C = Record<string, any>, E = Record<string, any>> = ExecutionResult & {
extensions?: E;
context?: C;
};
graphql
ExecutionResult
:
export interface ExecutionResult {
data?: { [key: string]: any };
extensions?: { [key: string]: any };
errors?: GraphQLError[];
}
Summary
data
- Themutate<T>
fromapollo-client
doesn’t type the result, it typesFetchResult<T>
position 1, which is thecontext
. The result is inExecutionResult
which is entirely unsealed/untypeddata?: { [key: string]: any }
variables
-MutationOptions<T>
doesn’t allow for typing of variables - they are explicitlyany
export interface MutationBaseOptions<T = {
[key: string]: any;
}> {
optimisticResponse?: Object | Function;
updateQueries?: MutationQueryReducersMap<T>;
refetchQueries?: ((result: ExecutionResult) => RefetchQueryDescription) | RefetchQueryDescription;
update?: MutationUpdaterFn<T>;
errorPolicy?: ErrorPolicy;
variables?: any;
}
export interface MutationOptions<T = {
[key: string]: any;
}> extends MutationBaseOptions<T> {
mutation: DocumentNode;
context?: any;
}
- I suggest any parameterized type named
T
be renamed for clarity to expose issues such as this.
Version
- apollo-client@2.0.4
Issue Analytics
- State:
- Created 6 years ago
- Reactions:17
- Comments:21 (10 by maintainers)
Top Results From Across the Web
variables lose their labels after mutate() function is applied in R
When I apply mutate() functions on any column, that column loses its label. library(dplyr) df2 <- df1 %>% mutate_if(is.character ...
Read more >Create, modify, and delete columns — mutate • dplyr
mutate () adds new variables and preserves existing ones; transmute() adds new variables and drops existing ones. New variables overwrite existing variables ......
Read more >Understanding type annotation in Python - LogRocket Blog
With type hints, you can annotate variables and functions with datatypes. Tools like mypy, pyright, pytypes, or pyre perform the functions ...
Read more >Real world advice for writing maintainable Go programs
Functions or methods that begin with Write traditonally take non string values and write them out as binary data. Collection variables, maps ...
Read more >How to Use Mutate function in R - R-bloggers
The dplyr library has the following functions that can be used to add additional variables to a data frame. mutate() – adds new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have tested the PR locally via augmentation with:
It seems to be working out of the box since apollo-client was trying to pass through the the
TData
as position 1, albeit errantly as it was applied toC
. By adding the above in the PR, it-just-works. Hopefully the apollo-link PR is merged/released.Our team is having issues with this bug, no typings on mutation. We are using apollo-link 1.2.11. Created a stackblitz to illustrate the issue: https://stackblitz.com/edit/apollo-no-typings-on-mutation
@rosskevin are we not expecting typings to work here?