Skip to content
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

FetchtResult for mutation #1477

Open
fetis opened this issue Mar 17, 2020 · 2 comments
Open

FetchtResult for mutation #1477

fetis opened this issue Mar 17, 2020 · 2 comments

Comments

@fetis
Copy link
Contributor

fetis commented Mar 17, 2020

Holla!

.mutate() method of apollo-angular uses FetchResult<T> for the return type, which internally uses ExecutionResult<T> from graphql module itself. The data property in ExecutionResult defined as optional and nullable. This brings problems because TS always complain that data might be null even when your mutation result is neve nullable (we use types generated from the schema). So you have to fight with nullability and of course, it's confusing because the schema result is non-nullable.

In contradiction query method defines data as data<T>, so we don't have this problem for queries.

What would be a solution to this?

@fetis fetis changed the title FetchtResutl for mutation FetchtResult for mutation Mar 17, 2020
@psyphore
Copy link

psyphore commented Apr 4, 2020

for some reason, the apollo-angular docs have been neglected, so this is how I read the data from a mutation result:

`
private apolloAuthenticated = new BehaviorSubject(null); // declare subject
public signIn(credentials: SignInCredentials) {
this.apollo
.mutate<SignInResponse, SignInCredentials>({
mutation: SIGN_IN_MUTATION,
variables: { creds: credentials.creds },
update: (proxy, { data }) => {
this.apolloAuthenticated.next(data); // update the subject here
}
}).subscribe();

return this.apolloAuthenticated.asObservable();

}

// consume the subject
return this.dataService.signIn(payload)
.pipe(
tap((data) => data ? dispatch(new SignInSuccess(data)) : null),
catchError((error) => of(dispatch(new SignInFailure(error.message))))
);
`

@fetis
Copy link
Contributor Author

fetis commented Apr 6, 2020

@psyphore thanks for a comment, but I'm not sure it solves my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants