-
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
TS type of "previousQueryResult" on updateQuery #3391
Comments
The TS types overall could definitely use some work. |
We ❤️ pull requests! 😉 |
@hwillson cool! Will need some time to get into, but really like to help! |
@nilshartmann @hwillson here is a PR for a temporary "band-aid" to improve these types immediately for I also created an issue to clean up these types in the These types still aren't released in |
@skovy looks good, thank you so much! I am not sure how I discovered the file in my original comment (somehow by blindly following VSCode navigations 😉) Regarding #3140 (I think...): when using
This seems not be addressed in 3140? |
I think I just ran into a similar issue when trying to read the result of a mutation: Type 'void | FetchResult<LogInData, Record<string, any>>' is not assignable to type 'LogInData'.
Type 'void' is not assignable to type 'LogInData'. Code looks something like this, and I'm struggling to get it working. import * as React from 'react'
import { Mutation } from 'react-apollo'
import gql from 'graphql-tag'
import LogInForm from './LogInForm'
const LOG_IN = gql`
mutation logIn($email: String!, $password: String!) {
logIn(email: $email, password: $password) {
_id
email
password
jwt
}
}
`
interface LogInData {
data: {
logIn: {
_id: string,
email: string,
password: string,
jwt: string,
}
}
}
interface LogInVariables {}
class LogInMutation extends Mutation<LogInData, LogInVariables> {}
export interface LogInFormContainerProps {}
export default class LogInFormContainer extends React.Component<
LogInFormContainerProps,
any
> {
public render() {
return (
<LogInMutation mutation={LOG_IN}>
{(logIn, { data }) => (
<LogInForm
/* tslint:disable */
handleOk={async (values: any) => {
console.log('LogInFormContainer values')
console.log(values)
const res = await logIn({ variables: { ...values } })
console.log('res', res)
// error!!!!
localStorage.setItem('token', res.data.logIn.jwt);
}}
/* tslint:enable */
loading={false}
/>
)}
</LogInMutation>
)
}
} I'm quite new to TS, so it could just be that I've misunderstood how things are supposed to work. |
I had the same issue today. Basically the mutation promise can return void or data. You are assuming that it will return data always and that's why the TS error. Fix is quite simple actually |
Thanks for reporting this. There hasn't been any activity here in quite some time, so we'll close this issue for now. If this is still a problem (using a modern version of Apollo Client), please let us know. Thanks! |
Hello,
when using the
updateQuery
function onsubscribeToMore
(that gets passed as prop to the render prop fromQuery
), the first argumentpreviousQueryResult
is in TypeScript defined asObject
:apollo-client/packages/apollo-client/src/core/watchQueryOptions.ts
Line 102 in eb78ab9
Wouldn't it make sense that previousQueryResult is of the same type as the
Query
result type?Example:
Version
The text was updated successfully, but these errors were encountered: