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.25k stars 620 forks source link

How to setup Proxy in GraphQL #1256

Open Adarsh2692 opened 1 year ago

Adarsh2692 commented 1 year ago

In the issue https://github.com/zino-hofmann/graphql-flutter/issues/951 , it is mentioned to use following code to setup proxy in GraphQL :

HttpClient httpClient = HttpClient(); httpClient.findProxy = (uri) { return "PROXY localhost:3128;"; }; var link = HttpLink(baseUrl, httpClient: httpClient); var client = GraphQLClient( cache: GraphQLCache(), link: link, );

While implementing this, I constantly keep on getting the following error : The argument type 'HttpClient' can't be assigned to the parameter type 'Client?'

Please look into this and help me with a solution that works

@vincenzopalazzo , do we have a resolution to this? In the following comment you have mentioned that you will be working on a similar issue https://github.com/zino-hofmann/graphql-flutter/discussions/1018#discussioncomment-3762682

vincenzopalazzo commented 1 year ago

I need to look inside it, now I did not remember

Dohmanlechx commented 1 year ago

Wondering the same thing, following...

ishiahirake commented 1 year ago

While implementing this, I constantly keep on getting the following error : The argument type 'HttpClient' can't be assigned to the parameter type 'Client?'

convert HttpClient to IOClient will solve this problem.

import "package:http/io_client.dart";

HttpClient httpClient = HttpClient();

httpClient.findProxy = (uri) {
  return "PROXY $proxy;";
};

// Pass your newly instantiated HttpClient to http.IOClient.
return IOClient(httpClient);

referenced from here