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

Not getting response in Mutation. #1217

Closed sarangi12 closed 2 years ago

sarangi12 commented 2 years ago

I am trying to call Mutation method with MutationOptions. Method and query are as follow. Method:

final graphql.MutationOptions options =
        graphql.MutationOptions(document: graphql.gql("""
           mutation {
       createPost(
    spaceId: "id",
    input: {
      postTypeId: "type"
      mappingFields: [
        {
          key: "title"
          type: text
          value: "title"
        },
        {
          key: "content"
          type: text
          value: "content"
        }
      ]
      publish: true
    }
  ) {
    id
  }
    }

      """));
    var result = await fluttergql.GraphQLClient(
      cache: fluttergql.GraphQLCache(),
      link: _link,
    ).mutate(options);
    print("============> ${result.toString()}");
  }

Response:

QueryResult(source: QueryResultSource.network, data: null, context: Context({ResponseExtensions: Instance of 'ResponseExtensions', HttpLinkResponseContext: Instance of 'HttpLinkResponseContext'}), exception: OperationException(linkException: null, graphqlErrors: [GraphQLError(message: Validation Params Failed, locations: null, path: null, extensions: null)]), timestamp: 2022-08-29 11:03:51.778335)

Data is null while GraphQl showing error "Validation Params Failed" while Query is working i confirmed with other app.

Please guide me through this.

budde377 commented 2 years ago

This is a server error and not a bug in the library. Try and validate your mutation in other clients, or reach out for help on our discord channel.

sarangi12 commented 2 years ago

Can you guide how to validate mutation?? As I Check the query, It's working, just not getting response in flutter only.

budde377 commented 2 years ago

Can you guide how to validate mutation??

Try and perform your mutation in a different client (e.g. postman) and see if this is only happening in this client.

As I Check the query, It's working,

How are you "checking" your query? How do you verify that this is working?

just not getting response in flutter only.

It is working though. You're getting an error from the server because your mutation is invalid.

sarangi12 commented 2 years ago

I have checked query in Postman Its working fine getting response in Postman also

budde377 commented 2 years ago

Do you have a screenshot of this?

sarangi12 commented 2 years ago

Check this screenshots, It's not passing the value which cases error. Do you have any suggestion how to pass it?

Result in postman: Screenshot from 2022-08-29 15-27-33

Error in flutter: Screenshot from 2022-08-29 15-28-14

budde377 commented 2 years ago

Cool. First off, I can't verify that these two requests are the same because you've decided to crop the message.

Secondly, the second screenshot is now a different error (which is caused by you not escaping your quotes properly).

sarangi12 commented 2 years ago

Yes, I got it. As i'm new to graphql, i don;t have much idea about this. Can you guide me how can i get rid of this error. I have trying to resolve this since last few days. Can you help me, How can i pass this query.

 final graphql.MutationOptions options =
        graphql.MutationOptions(document: graphql.gql("""
           mutation {
       createPost(
    spaceId: "spaceid",
    input: {
      postTypeId: "id"
      mappingFields: [
        {
          key: "title"
          type: text
          value: "\"Hi, eveyone\""
        },
        {
          key: "content"
          type: html
          value: "\"<p>Good Afternoon</p>\""
        }
      ]
      publish: true
    }
  ) {
    id
  }
    }

      """));
    var result = await fluttergql.GraphQLClient(
      cache: fluttergql.GraphQLCache(),
      link: _link,
    ).mutate(options);
budde377 commented 2 years ago

I'm trying to help you. If you'd please share the screenshot of executing exactly the same mutation in postman.

sarangi12 commented 2 years ago

In this query , in mappingFields and in value , I need send json string, which I am unable to send.

Here is a screenshot of exact same query from postman,

image

Here, what I am trying to send in flutter

image

budde377 commented 2 years ago

Your mutation itself is a string and you're not escaping your double quotes properly. This is not a graphql problem but a problem with how you're using dart.

You have different ways of escaping your \, the easiest probably is to prefix your mutation with r. This'll treat the string as a raw string which will not read your backslash as trying to escape your quote.

For example, take the program

print("hello"); // prints hello
print("\"hello\""); // prints "hello"
print("\\\"hello\\\""); // prints \"hello\"
print(r"\"hello\""); // prints \"hello\"
sarangi12 commented 2 years ago

I tried putting 'r' It's giving me this error:

QueryResult(source: QueryResultSource.network, data: null, context: Context({}), exception: OperationException(linkException: ServerException(originalException: null, parsedResponse: Response(data: null, errors: [GraphQLError(message: Syntax Error: Expected ":", found Name "everyone"., locations: null, path: null, extensions: null)], context: Context({ResponseExtensions: Instance of 'ResponseExtensions'}), response {errors: [{message: Syntax Error: Expected ":", found Name "everyone"., code: 10, timestamp: 2022-08-30T12:45:49.283Z}]})), graphqlErrors: []), timestamp: 2022-08-30 18:15:49.284640)

image

budde377 commented 2 years ago

So this is, again, a server error. I don't know why it won't accept your data as I don't know what api you're developing against. But it is not an error in this framework.

I can see that you've changed the mutation from when you called with postman, so have you tried:

  1. Changing it back, I.e. adding the comma between Hi and everyone?
  2. Restarting your app
sarangi12 commented 2 years ago

I tried all possible solutions, but didn't get success.

But thanks for your help.

budde377 commented 2 years ago

If you need more help, feel free to reach out on our discord.