graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Mutations returning Bad Request

Open soundling opened this issue 2 years ago • 11 comments

I can't find what I'm doing wrong with mutations, simple queries are working well but I have no luck with mutations. Am I formating it properly ? Any help is welcome! 2021-08-06 10_56_07-Window

soundling avatar Aug 06 '21 08:08 soundling

Typo in the operation name?

I'd also recommend to input the whole input object as a variable...

rose-a avatar Aug 06 '21 10:08 rose-a

Typo in the operation name?

I'd also recommend to input the whole input object as a variable...

I tried to correct the operation name, still not going thru, where could I find a proper example for mutations? I tried everything I can think of ... 2021-08-06 13_29_24-Window

soundling avatar Aug 06 '21 11:08 soundling

I thought I had fixed it, but actually I was using an other RestSharp client, not this client... Still can"t manage to get it working ...

2021-08-06 15_08_44-Window

soundling avatar Aug 06 '21 13:08 soundling

Well... check whats happening on the server side now... you're getting an InternalServerError now!

rose-a avatar Sep 16 '21 21:09 rose-a

In my case, I get a bad request because the title case of variable properties isn't matched.

the object I have on server is:

interface IInputPhone {
  name: {
    en: string
  }
  description: {
    en: string
  }
}

From client side, this GraphQLRequest gets a Bad Request:

        var gqlRequest = new GraphQLRequest
        {
            Query = mutation,
            OperationName = "createPhoneContent",
            Variables = new
            {
                inputPhone = new
                {
                    Name = new
                    {
                        En = "iPhone"
                    },

                    Description = new
                    {
                       En = "iPhone test"
                    }
                }
            }
        };

While this is working:

        var gqlRequest = new GraphQLRequest
        {
            Query = mutation,
            OperationName = "createPhoneContent",
            Variables = new
            {
                inputPhone = new
                {
                    name = new
                    {
                        en = "iPhone"
                    },

                    description = new
                    {
                       en = "iPhone test"
                    }
                }
            }
        };

valorad avatar Jun 19 '22 16:06 valorad

in my case the Input parameter is null at resolver. I'm exploring graphql for the first time, honestly i don't know what's wrong with it. Captura de pantalla 2023-05-07 200049 Captura de pantalla 2023-05-07 200025

orlandommb avatar May 08 '23 00:05 orlandommb

How do you handle incoming GraphQL requests in your server?

rose-a avatar May 08 '23 07:05 rose-a

How do you handle incoming GraphQL requests in your server?

All i have is the basic configuration of graphql, im using HotChocolate 13, i'm not using app.MapEndpoints or anything related to routing, i just have app.MapGraphQL, and the mutation where i have that specific resolver is an ExtendedObjectType.

orlandommb avatar May 08 '23 15:05 orlandommb

I can't help you with HotChocolate, I've never used it myself (I'm using GraphQL .NET).

But I suspect it's most likely a serialization/deserialization issue. Make sure your UserInfo object serializes exactly to your expected JSON object (take a look at the Serializer Tests on how you might check that).

And then make sure the server correctly deserializes it again.

rose-a avatar May 08 '23 18:05 rose-a

I can't help you with HotChocolate, I've never used it myself (I'm using GraphQL .NET).

But I suspect it's most likely a serialization/deserialization issue. Make sure your UserInfo object serializes exactly to your expected JSON object (take a look at the Serializer Tests on how you might check that).

And then make sure the server correctly deserializes it again.

Thank you for the help ! i'll take a look at the tests !

orlandommb avatar May 09 '23 01:05 orlandommb

I see that your payloads from https://github.com/graphql-dotnet/graphql-client/issues/360#issuecomment-1159765925 differ only in case so I'm sure this is a well-known problem with serialization/deserialization. Server accepts name and description in lower case. I've never used HotChocolate as well but in GraphQL.NET I faced the same issue sometimes.

sungam3r avatar May 09 '23 06:05 sungam3r