-
Notifications
You must be signed in to change notification settings - Fork 121
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
RequestControllerTypedLink return subscription streams that can end #629
RequestControllerTypedLink return subscription streams that can end #629
Conversation
✅ Deploy Preview for ferry-gql ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Corresponding issue for this PR: |
Update RequestControllerTypedLink so that it will not refetch and return the stream result directly. This allows the stream to end if the server completes the stream, and the listeners `onData` will fire.
5b27925
to
32fe45e
Compare
Hi! Please add a test that ensures that this new behavior will not break in the future. should be something like group('done event for subscriptions', () {
late TypedLink typedLink;
setUp(() {
typedLink = TypedLink.from([
RequestControllerTypedLink(),
TypedLink.function(<TData, TVars>(request, [next]) =>
Stream<OperationResponse<TData, TVars>>.empty()),
]);
});
test('onDone is propagated for subscriptions', () {
final stream = typedLink.request(
JsonOperationRequest(
fetchPolicy: FetchPolicy.NetworkOnly,
vars: {},
operation: Operation(
document: gql.parseString(r'''
subscription Sub {
reviews {
id
stars
}
}'''),
),
),
);
expect(stream, emitsInOrder([emitsDone]));
});
}); |
Added test to verify that the subscription done event is emitted through the RequestControllerTypedLink
I appreciate the example on this one! I added the test to validate that the RequestControllerTypedLink is passing along the stream done |
Thanks! |
Update RequestControllerTypedLink so that it will not refetch and return the stream result directly. This allows the stream to end if the server completes the stream, and the listeners
onData
will fire.Since the requestController stream never closes the switchMap's result stream will also never reach the onDone state. This uses only the first matching requestController emitted request when it is a subscription operation. This allows the switchMap's resulting stream to close when the server's response stream closes as well.