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

I had an issue: 'Property __typename on Query does not exist' #1215

Closed SalihCanBinboga closed 2 years ago

SalihCanBinboga commented 2 years ago

Describe the issue A clear and concise description of what the problem is.

To Reproduce (MUST BE PROVIDED)

When I run the below code snippet I have the below error:

` final HttpLink httpLink = HttpLink( '$baseUrl/graphql', );

final AuthLink authLink = AuthLink(
  getToken: () async =>
      'Bearer $accessToken',
);

final Link link = authLink.concat(httpLink);

final GraphQLClient client = GraphQLClient(
  cache: GraphQLCache(),
  link: link,
);

const String readCategories = r'''

query GetCarCategories($parentId: Int!){ getCarCategories(parentId: $parentId) { id title } } ''';

final QueryResult<Object?> resulttt = await client.query(
  QueryOptions(
    document: gql(readCategories),
    variables: const <String, dynamic>{
      'parentId': 101,
    },
  ),
);

if (resulttt.hasException) {
  print(resulttt.exception.toString());
  /*
  OperationException(linkException: null, graphqlErrors: [
  GraphQLError(message: Property __typename on Query does not exist, 
  locations: [ErrorLocation(line: 2, column: 3)], path: [], extensions: null)])
   */
}`

Expected behavior I want to expect clear response.

device / execution context I have tried real device on ios. Remote server.

budde377 commented 2 years ago

gql is adding the property __typename on every selectionset. It looks like your server doesn't support introspection on the Query type. Either enable introspection or use another implementation of gql. If you do not support the __typename introspection field in general, you can not expect caching to work properly.

SalihCanBinboga commented 2 years ago

@vincenzopalazzo @budde377 But I can add __typename parameter in my own query manager?w

budde377 commented 2 years ago

Okay. I'm not sure what to tell you. The error message is from your server, it complains that you're trying to query Query.__typename. So you have two options:

vincenzopalazzo commented 2 years ago

+1 for fix your server