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.24k stars 612 forks source link

Errors out when useGETForQueries is enabled in HTTPLink #1302

Open nevenerep opened 1 year ago

nevenerep commented 1 year ago

Describe the issue Can't query when using useGETForQueries: true on HTTPLink. I've tried this with multiple endpoints. These endpoints work fine when I test them out using the JS Apollo Client with the same setting. If you disable the setting, the query executes with no issues.

To Reproduce (MUST BE PROVIDED)

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

void main() async {
  final HttpLink httpLink = HttpLink(
    'https://countries.trevorblades.com', // Public endpoint
    useGETForQueries: true
  );

  final AuthLink authLink = AuthLink(
    getToken: () async => null,
  );

  final Link link = authLink.concat(httpLink);

  ValueNotifier<GraphQLClient> client = ValueNotifier(
    GraphQLClient(
      link: link,
      // The default store is the InMemoryStore, which does NOT persist to disk
      cache: GraphQLCache(),
    ),
  );

  final value = await client.value.query(QueryOptions(
    document: gql('''
      query{
        countries{
          code
        }
      }
    ''')
  ));

  print(value);

  runApp(const MyApp());
}

Expected behavior Should work.

device / execution context Pixel 6 Emulator on Android S Also tried Flutter Web using Chrome, same result.

Other useful/optional fields

Here is what the debug console prints out:

QueryResult(source: QueryResultSource.network, data: null, context: Context({}), exception: OperationException(linkException: ServerException(originalException: null, originalStackTrace: null, parsedResponse: Response(data: null, errors: [GraphQLError(message: Cannot read properties of undefined (reading 'operation'), locations: null, path: null, extensions: {code: INTERNAL_SERVER_ERROR})], context: Context({ResponseExtensions: Instance of 'ResponseExtensions'}), response {errors: [{message: Cannot read properties of undefined (reading 'operation'), extensions: {code: INTERNAL_SERVER_ERROR}}]})), graphqlErrors: []), timestamp: 2023-03-09 12:04:03.581)

screenshots

additional context

additional notes

vincenzopalazzo commented 1 year ago

Looks like a server error? response {errors: [{message: Cannot read properties of undefined (reading 'operation'), extensions: {code: INTERNAL_SERVER_ERROR}}]}))