zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.24k stars 612 forks source link

There was an error causing connection lost: Bad state: No element #1296

Closed large closed 1 year ago

large commented 1 year ago

Describe the issue Using the GraphQLProtocol.graphqlTransportWs gives "No element" error when fetching data from Tibber.

Tibber uses GraphQL to provide livedata stream from their power reader. An Api explorer is available here: https://developer.tibber.com/explorer Note: Press "Load demo token" and "Load example query" to "realtime subscription", press play. See the data I am trying to reach.

To Reproduce

Code says a lot and related to the API docs https://developer.tibber.com/docs/overview#breaking-websocket-change I need to fetch the wss:// address first (which works fine) and then split with a subscription query.

Expected behavior When subscribed the data received should be the same as the API Explorer.

Device / execution context iOS emulator, no localhost issues since everything is online.

Other useful/optional fields

I have rather limited background using GraphQL so this could a "beginners error". If so I hope some more experienced could show / describe what the error message actually is?

Tibber has some requirements, and setting the user-agent was not an option I found:

Websocket subscription client requirements

Clients must set user-agent header when calling GraphQL API and when opening websocket connection. Both platform and driver version must be indicated. E.g. Homey/10.0.0 com.tibber/1.8.3 Clients must implement graphql-transport-ws sub-protocol Clients must implement jitter and exponential backoff when retrying requests to API Clients must dynamically query websocket server url

large commented 1 year ago

Fixed the problem myself, the websocket needed to have auth in header too. Did not work with combine function