-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Add support for request progress #526
Comments
If you're interested in posting a PR, I could guide you and give some help. Just let me know. |
@kamilkisiela I would like to work on it. Here is my thought how to implement it:
Could you please look through and give your opinion? Thanks. |
If it's disabled by default then sure, let's do it. Make sure user can enable/disable not only in Link's config but also through operation's context. |
I've faced with two minor issues, that I don't know how to solve correct. Since in tests @kamilkisiela Could give me piece of advice?
What is operation's context? Thanks. |
@artem-galas https://github.com/artem-galas/apollo-angular/pull/1 I'm interested how you will ship the progress value to the consumer. Apollo.query and Apollo.watchQuery both resolve with |
@kamilkisiela Thanks for your help. Yes, I'm also interested how to deliver that functionality to consumer.... I'm thinking to make What do you think? |
@artem-galas Maybe a directive (let's say Can I ask why you guys need to access this http progress thing? Can't that be done within http interception? |
To be honest I hardly ever use Regarding directive
|
I would really like to have this option without a "hack", but in this case I had to use rest. |
I would also like to have this option. In our application we upload files that have 1GB. We use https://github.com/jaydenseric/graphql-multipart-request-spec for this together with apollo-upload-client but I use the interceptor "the hacky way" to track progress. |
For those who want to be able to get the upload progress of files to their GraphQL endpoint yet don't want to hack around with apollo-upload-client, my solution was to simply reimplement the upload mutation using Angular's Something like this: import { HttpClient, HttpEventType, HttpResponse } from '@angular/common/http';
import { FetchResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';
import { print } from 'graphql';
import { from, throwError } from 'rxjs';
import { filter, map, switchMap, tap } from 'rxjs/operators';
import { MutationError, UploadFileGQL, UploadFileMutation } from 'src/graphql';
const formData = new FormData();
formData.append(
'operations',
JSON.stringify({
query: print(this.uploadFileGql.document),
variables: {
file: null,
},
}),
);
formData.append(
'map',
JSON.stringify({
file: ['variables.file'],
}),
);
formData.append('file', file, file.name);
this.http
.post('/graphql', formData, {
reportProgress: true,
observe: 'events',
})
.pipe(
tap((event) => {
if (event.type === HttpEventType.UploadProgress) {
// You can get the upload progress here!
console.log(Math.round((100 * event.loaded) / event.total!));
}
}),
filter((event) => event.type === HttpEventType.Response),
switchMap((event) => {
const body: FetchResult<UploadFileMutation> = (<HttpResponse<any>>event).body!;
if (!body.errors) {
// This query refetching is optional and is only available in Apollo client 3.4+.
return from(this.apollo.client.refetchQueries(['SomeQueriesToRefetch'])).pipe(map(() => body));
} else {
return throwError(body.errors);
}
}),
)
.subscribe(
({ data }: FetchResult<UploadFileMutation>) => {
},
); |
Any update on this? :/ |
Is there any update on this? |
No progress on this issue. It won't happen unless somebody make a PR for it. One limitation to be aware of is that reportProgress for upload seems to be impossible for people using |
Angular now provides support for monitoring the progress of HTTP requests through an observable.
https://angular.io/guide/http#listening-to-progress-events
It would be great if this could be exposed through apollo-angular.
The text was updated successfully, but these errors were encountered: