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

Any query fails with an error message #1115

Closed HTMHell closed 2 years ago

HTMHell commented 2 years ago

Describe the issue I'm getting this error for any query I'm trying to run:

OperationException(linkException: null, graphqlErrors: [GraphQLError(message: prepared statement "ee3e1f16e73f409ba03b64d276e43fe2" does not exist, locations: null, path: null, extensions: null)])

To Reproduce (MUST BE PROVIDED)

Example of a query:

    const String query = r'''
      query MyQuery($id: String!) {
        profilesCollection(filter: {id: {eq: $id}}) {
          edges {
            node {
              id
              username
            }
          }
        }
      }
    ''';

    final QueryOptions options = QueryOptions(
      document: gql(query),
      variables: <String, dynamic>{
        'id': id.getOrCrash(),
      },
    );

    final QueryResult result = await _graphqlClient.query(options);

Expected behavior Should not return an error.

device / execution context Running a flutter app on an iOS simulator.

additional context

budde377 commented 2 years ago

prepared statement "ee3e1f16e73f409ba03b64d276e43fe2" does not exist

Sounds like you have some database problems on your backend.

HTMHell commented 2 years ago

prepared statement "ee3e1f16e73f409ba03b64d276e43fe2" does not exist

Sounds like you have some database problems on your backend.

When I send the same requests from other clients I'm not getting an error

budde377 commented 2 years ago

When I send the same requests from other clients I'm not getting an error

I can't speak to your server implementation, but this is a server error.

vincenzopalazzo commented 2 years ago

When I send the same requests from other clients I'm not getting an error

You can take into account that the token or id that you are passing to graphql flutter is wrong, and maybe the problem is in your dart code.

More importantly, all the value that you pass to graphql_flutter are final, this means that they never change

HTMHell commented 2 years ago

When I send the same requests from other clients I'm not getting an error

You can take into account that the token or id that you are passing to graphql flutter is wrong, and maybe the problem is in your dart code.

More importantly, all the value that you pass to graphql_flutter are final, this means that they never change

The thing is, I'm 100% sure it's the same parameters, and it works through other clients. So I'm thinking it probably has something to do with how the request is being parsed? maybe it's being sent a bit differently. So I started debugging and I came across this:

image

Could it have anything to do with this?

budde377 commented 2 years ago

I don't see anything wrong in your screenshot. Have you considered calling against a mock server to inspect what's sent? Beeceptor or similar?

HTMHell commented 2 years ago

I don't see anything wrong in your screenshot. Have you considered calling against a mock server to inspect what's sent? Beeceptor or similar?

Thanks, it was a very helpful idea! The difference between the requests is that this package adds __typename multiple times in the query, while other clients do not add it at all.

GraphiQL/Postman:

query MyQuery($id: String!) {
    profilesCollection(filter: {id: {eq: $id}}) {
        edges {
            node {
                id
                username
            }
        }
    }
}

This package:

query MyQuery($id: String!) {
  __typename
  profilesCollection(filter: {id: {eq: $id}}) {
    __typename
    edges {
      __typename
      node {
        __typename
        id
        username
      }
    }
  }
}

I reproduced the same error while sending that request via PostMan, and I realized this is happening because of the first __typename, the one right before profilesCollection.

I'm very new to GraphQL so I'm not sure if it's valid or not, but I guess if it was invalid then I would get a parser error. So it's entirely a server-side problem?

Thank you for your help.

vincenzopalazzo commented 2 years ago

The __typename is a valid graphql https://graphql.org/learn/queries/#meta-fields and we use is a lot because help the package to understand the return type.

So this is a server error that doesn't accept this __typename and it is wrong.