Closed CrispenGari closed 1 year ago
If you can create a reproduction in isolation I'm happy to take a look, however, there's no logic that isn't common between React and React Native bindings as they're identical. I can't accept pasted code snippets as a reproduction for an issue as such.
Are you aware as well that your authExchange
isn't actually used for the fetchExchange
?
I'll also suggest to check whether you have a duplicate and outdated version installed for @urql/core
as there's an old bug associated with this.
Lastly, there are two known issues associated with React Native. One probably doesn't matter in this case, unless you haven't checked error.networkError
, which shouldn't be the case here. The other is that React Native used to cause issues when some kind of Promise
collapse happens.
Specifically, we used to see issues when AsyncStorage
is called and in its promise resolution fetch
is called subsequently. Have you isolated the issue by removing your auth code?
Edit: Lastly, actually, have you tried what happens when you don't use GraphQL SSE? The transport is built into urql and, with some restrictions, both the multipart and SSE response protocols can be used in urql (e.g. when you're using GraphQL Yoga) without any additional packages by enabling fetchSubscriptions: true
on the Client
https://github.com/urql-graphql/urql/tree/main/examples/with-subscriptions-via-fetch
@kitten Thanks Phil, do you mind if i can share the github link to my project so that you can have a look at it and see where am not configuring the client correctly.
And i might also need a good explanation, on Are you aware as well that your authExchange
isn't actually used for the fetchExchange
? How is that so ?
The importance of order of exchanges is repeated throughout the documentation quite a lot, so please read it carefully 😅
Exchanges are used in order and process operations in order (forwards) and then send or process results in order (backwards).
As such, your fetchExchange
handles queries without the authExchange
ever seeing them. But you also define both fetchOptions
and an authExchange
. The latter should override the former, but only if it handles an operation.
I can't accept a full app as a reproduction, sorry. If I ran everyone's apps, debug, and narrow down issues for them, that skips the most important step and causes me to basically spend hours on understanding and running your app, and to then create a reproduction myself.
A reproduction means that you've isolated the issue to a minimal piece of code that not only causes the issue, but can be used to pinpoint it.
Sorry, but without any indication of what this issue is, I can't commit to doing that myself 😅
@CrispenGari Hiya 👋
Just to point some things out, since I've had more time to think about this. I'm not sure how graphql-sse
handles this, but I'm not fully convinced that Fetch streams are supported by React Native, see: https://github.com/facebook/react-native/issues/27741
I don't know if graphql-sse
has a fall back that is supported, but I can at least say that the built-in implementation that @urql/core
has for SSE and multipart streamed responses will not work on React Native given this limitation.
The only way to (probably) work around this would be for graphql-sse
to explicitly allow for EventSource
to be used and plugged in — however, afaik, their implementation is also based on fetch
’s async iterable / body stream API.
You could attempt to basically use this library to basically “ponyfill” this functionality into your app, but it'd require implementing either a GraphQL SSE-like implementation or a whole urql Exchange. https://github.com/binaryminds/react-native-sse
However, overall, I don't think it's reasonable for either graphql-sse
or us to maintain code to use XMLHttpRequest
or EventSource
via a polyfill like this one, to restore this functionality for React Native, as it'd be expected for the “host platform” to support async fetch response streams.
So, given the inactivity, I'll go ahead and will close this for now, but happy to take more comments here if you have any further questions 🙌
Edit: @enisdenjo; there is a sample of creating your own EventSource
against your API, as long as you'd use EventSource
from react-native-sse
, e.g.:
const url = new URL('http://localhost:4000/graphql');
url.searchParams.append('query', 'subscription { greetings }');
const source = new EventSource(url);
source.addEventListener('next', ({ data }) => {
console.log(data); // { "data": { "greetings": "Hi" } }
});
source.addEventListener('complete', () => {
source.close();
});
So, if you're willing to wrap this yourself, you could implement this yourself
Quick update 👋
@enisdenjo kindly posted an example of how to hook up a standard EventSource
API on the client to a GraphQL over SSE API: https://the-guild.dev/graphql/sse/recipes#with-eventsource-distinct-connections-mode
Describe the bug
I'm using the
urql
implementation to with graphql-sse to create a graphql client as follows:Then when try to use the
useSubscription
hook as follows to listen to new incoming subscriptions in my component as follows:In my logs in a react-native application i'm only getting the loading state to
true
as follows:But in my React web app when a new subscription is fired i'm getting the expected results as follows:
Why am i getting this different behaviour in react-native?.
Reproduction
None
Urql version
urql v^2.1.4
Validations