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 623 forks source link

Exception but with Response Data , OperationException #1293

Open sulthanalihsan opened 1 year ago

sulthanalihsan commented 1 year ago

Hi, thankyou for making this excellent package

i have a question about my error, previously i have successfully request to the server, but I didn't get a response and get the error as below, It can be see that there is response in that error

{39FE66B6-3738-4860-A703-2F7290A7FEBC}

the error Cuplikan layar 2023-01-26 211349

I also tried something like this {80B58EED-81C1-4FCC-AAA7-9BBE4820CAD5}

what is wrong with my code? thanks

axelrogg commented 1 year ago

Hi, @sulthanalihsan, where you able to fix this? I'm currently having a similar issue. The debugger throws the following error: HttpLinkServerException and I haven't had any luck catching it. I know for sure that the API server is not running so I expect to get this error. The problem is not being able to handle it. My code is below

void someFunc() async {
        try {
            final result = await client.mutate(
                MutationOptions(
                    document: gql(someMutation),
                    variables: <String, String>{
                        "var":  "value",
                    },
                    // This gets printed but result is not catched.
                    onError: (OperationException? error) => debugPrint(error),
                )
            );

        }  catch(err) {
           // We never get here.
            debugPrint(err);

        }
}
ghost commented 1 year ago

Isn't this a very old issue that was supposed to had been fixed in v3.0.0? @HofmannZ

atoncetti commented 1 year ago

@sulthanalihsan @axelrogg I was able to overcome this issue by unchecking "Uncaught Exceptions" from Breakpoints in vscode debugger. Suggested here

debugger

Give it a try.

Might be an issue with the vscode debugger, as we are technically "catching" the exception.

vincenzopalazzo commented 1 year ago

When open the issue please add the reproducer otherwise will be closed at some point when I will scan again the issue

ReinRaus commented 1 year ago

Reproducer

import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

void main() {
  //final HttpLink graphqlLink = HttpLink("https://graphql-pokemon2.vercel.app");
  final HttpLink graphqlLink = HttpLink("https://fake.link/graphql");

  final AuthLink authLink = AuthLink(getToken: () => null);
  final Link link = authLink.concat(graphqlLink);
  ValueNotifier<GraphQLClient> graphqlClient = ValueNotifier(
    GraphQLClient(
      link: link,
      cache: GraphQLCache(store: InMemoryStore()),
    ),
  );

  runApp(
    GraphQLProvider(
      client: graphqlClient,
      child: const MyApp(),
    ),
  );
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String data = "[not loaded...]";
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: ListView(children: [
          TextButton(
            onPressed: clickHandle,
            child: const Text("Load pokemons"),
          ),
          Center(child: Text(data)),
        ]),
      ),
    );
  }

  void clickHandle() {
    var gqlClient = GraphQLProvider.of(context).value;
    try {
      gqlClient
          .query(
            QueryOptions(
              document: gql("""
query {
  pokemons(first: 5) {
    name
  }
}
"""),
              onError: (error) => print(error),
            ),
          )
          .catchError((e) => print(e))
          .then((value) => setState(
                () => data = value.data!["pokemons"].toString(),
              ));
    } catch (e) {
      print(e);
    }
  }
}

Steps to reproduce:

  1. Run code example.

Problem

Exception dont catched with catch block or catchError in Future.