-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Typesafe Access to Mutation Result Not Working #2708
Comments
I guess that depends on your Schema - if the mutation result data is nullable, then it makes sense to generate "nullable" types as well. Most mutations can fail, and therefore might not always return a data object. Once optional chaining lands in Typescript (3.7), this access should be a bit cleaner. |
Yeah, I'm surprised this is happening since my schema marks the result as not nullable, which is why I'm reporting it here. Here's the schema: type Mutation {
signup(email: String!, password: String!, name: String!): AuthPayload!
login(email: String!, password: String!): AuthPayload!
} |
Which plugin are you using to generate your hooks? I think it might have to do with the hooks return value including |
Hi, i think it has to do with the fact that in the past data was {}, since version three they made the update that data is initially undefined :) See apollographql/react-apollo#3388 So the TypeScript feedback is solid, data can be undefined :)
|
@maapteh is right, Apollo changed the way they pass |
I may be missing something here, but I expect the data object returned by the mutation hook below to be built in such a way that I can easily access the other properties on the object, such as
response.data.login.token
, etc. Instead, when I try to access thelogin
object, Typescript tells me that I'm trying to access an object that may be undefined.Is this the expected behavior of the hook's results?
The text was updated successfully, but these errors were encountered: