My flutter project runs well on android but when trying to get it to web I get some troubles. I am using Graphql Faker as fake backend and it works well for android but for flutter web it always throw below error
╔╣ Request ║ POST
║ http://localhost:9002/graphql
╚══════════════════════════════════════════════════════════════════════════════════════════
╔╣ DioError ║ Status: 500 Internal Server Error
║ http://localhost:9002/graphql
╚══════════════════════════════════════════════════════════════════════════════════════════
╔ DioErrorType.RESPONSE
║ {
║ errors: [{message: invalid media type}]
║ }
╚══════════════════════════════════════════════════════════════════════════════════════════
Below is how client looks
GraphQLClient graphQLClient() {
final dio = Dio(
BaseOptions(
connectTimeout: 3 * 1000,
contentType: 'application/json',
),
);
final host = () {
try {
if (Platform.isAndroid) return MY_IP;
} catch (_) {}
return 'localhost';
}();
final graphqlEndpoint = 'http://$host:9002/graphql';
final WebSocketLink _wsLink = WebSocketLink('ws://$host:4000/graphql');
final Link _dioLink = DioLink(
graphqlEndpoint,
client: dio,
);
// split request based on type
final _link = Link.split(
(request) => request.isSubscription,
_wsLink,
_dioLink,
);
return GraphQLClient(
cache: GraphQLCache(),
link: _link,
);
}
Any comment/answer to fix this will be appreciated
This looks like a CORS error, the graphql-faker documentation has a section about cors: