Skip to content

Instantly share code, notes, and snippets.

@micimize
Last active August 27, 2021 15:06
Show Gist options
  • Save micimize/04ee011b445d38ce34193a5225992504 to your computer and use it in GitHub Desktop.
Save micimize/04ee011b445d38ce34193a5225992504 to your computer and use it in GitHub Desktop.
[OUTDATED] use SocketClientConfig.connect instead. old work around to headers for graphql flutter
@kateile
Copy link

kateile commented Apr 10, 2021

I love this workaround. any idea on how to make it work with ^5.0.0-nullsafety.2?

@micimize
Copy link
Author

@kateile As of 4.1.0-beta.1 you should be able to just pass a custom connect wrapper to the SocketClientConfig:

To supply custom headers to an IO client:

connect: (url, protocols) =>
  IOWebSocketChannel.connect(url, protocols: protocols, headers: myCustomHeaders)

@kateile
Copy link

kateile commented Apr 10, 2021

I am using 4.1.0-beta.1 along with gql_dio_link:^0.0.4 and dio: 3.0.10 and everything is fine. Dio 4 introduce some major fix for web and options for more secure cookies storage, and we uses session/cookies based auth. So migrating to dio 4 and latest gql_dio_link seems inevitable to me. Now the problem I am facing is turning this to work with ^5.0.0-nullsafety.2 because using 4.1.0-beta.1 seems incompatible with(I get solving version failed) other latest gql-dart dependencies. And version 5.0.0 uses different web socket package. My problem is I wish to upgrade packages but upgrading will break web socket since I can't pass headers.

@micimize
Copy link
Author

@kateile I admit I didn't read all that but gql_dio_link's been migrated to nullsafe+v4 so hopefully that will solve your issue.

@kateile
Copy link

kateile commented May 24, 2021

I still face some issues. Please see my comment here

@kateile
Copy link

kateile commented May 25, 2021

I did some little mistakes and I finally solved. Thank you so much

@micimize
Copy link
Author

good to hear 👍

@dunods
Copy link

dunods commented Aug 27, 2021

how do i apply this solustion to WSclient ?

final WSLink _webSocketLink = WSLink('ws://IP_ADDRESS/graphql',
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: null,
),
headers: {"authorization": "exampletoken"});

final Link _link = _webSocketLink;
final GraphQLClient _client = GraphQLClient(
link: _link,
cache: GraphQLCache(),
);

i did try but still unable to connect
any idea @kateile?

please help

@micimize
Copy link
Author

@dunods Use SocketClientConfig.connect – this is outdated and probably won't work now

@dunods
Copy link

dunods commented Aug 27, 2021

@micimize .. im using the old version graphql_flutter: ^4.0.0 and still yet that code didnt work out.. any idea how to make it work

@micimize
Copy link
Author

probably some dev environment setup issue, but I really recommend upgrading at least to 4.1.0-beta.1.

I no longer contribute to graphql_flutter so I don't have the details fresh in my head anymore

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