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.23k stars 613 forks source link

OperationException(linkException: ResponseFormatException(originalException: type 'Null' is not a subtype of type 'String' in type cast #1370

Open Routee opened 12 months ago

Routee commented 12 months ago
 enum TagType {
    Default,
    Private,
    Global,
    Abandon;
  }
 const String _createTag = r'''
    mutation CreateTag(
      $name: String!,
      $type: TagType!,
      $desc: String,
    ) {
        createTag(input: { name: $name, type: $type, desc: $desc }) {
          id
          name
          desc
          type
        }
    }
  ''';
MutationOptions createTag(Map<String, dynamic> variables) => MutationOptions(
    document: gql(_createTag),
    variables: variables,
    onError: (error) {
      print(variables);
      print('########');
      print(error);
    });

### it print the errors below

I/flutter (11467): {name: jj, desc: s, type: Default}
I/flutter (11467): ########
I/flutter (11467): OperationException(linkException: ResponseFormatException(originalException: type 'Null' is not a subtype of type 'String' in type cast, originalStackTrace: #0      ResponseParser.parseError (package:gql_link/src/response_parser.dart:29:35)
I/flutter (11467): #1      ResponseParser.parseResponse.<anonymous closure> (package:gql_link/src/response_parser.dart:13:34)
I/flutter (11467): #2      MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
I/flutter (11467): #3      ListIterator.moveNext (dart:_internal/iterable.dart:344:26)
I/flutter (11467): #4      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
I/flutter (11467): #5      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
I/flutter (11467): #6      new List.of (dart:core-patch/array_patch.dart:47:28)
I/flutter (11467): #7      ListIterable.toList (dart:_internal/iterable.dart:214:7)
I/flutter (11467): #8      ResponseParser.parseResponse (package:gql_link/src/response_parser.dart:15:14)
I/flutter (11467): #9      HttpLink._parseHttpResponse (package:gql_http_link/src/link.dart:118:21)
I/flutter (11467): <asynchronous suspension>
I/flutter (11467): #10     HttpLink.request (package:gql_ht
image

### it works on altair graphql client

image
Routee commented 12 months ago

i called the createTag in another file like this

import 'package:sparrow/network/graphql/tag/tag.dart' as client;
class TagController extends GetxController {
  void newTag() async {
      ... some code ...
      MutationOptions options = client.createTag(tagInput.value.toJson());
      var queryResult = await GraphQLProvider.of(context).value.mutate(options);
  }
}

this problems resolved when i modify the import name from

import 'package:sparrow/network/graphql/tag/tag.dart' as client;

to

import 'package:sparrow/network/graphql/tag/tag.dart' as tagClient;

when i rollback the tagClient to 'client', the exception was gone!!! looks like some cache problems.

Routee commented 11 months ago
image

if the backend throw a custom exception which message is null. this line: error['message'] as String will throw an excption. it's not the expected.