graphql-dotnet / graphql-client

A GraphQL Client for .NET Standard
MIT License
624 stars 134 forks source link

Mutations returning Bad Request #360

Open soundling opened 3 years ago

soundling commented 3 years ago

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

rose-a commented 3 years ago

Typo in the operation name?

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

soundling commented 3 years ago

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 commented 3 years ago

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

rose-a commented 3 years ago

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

valorad commented 2 years ago

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"
                    }
                }
            }
        };
orlandommb commented 1 year ago

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

rose-a commented 1 year ago

How do you handle incoming GraphQL requests in your server?

orlandommb commented 1 year ago

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.

rose-a commented 1 year ago

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.

orlandommb commented 1 year ago

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 !

sungam3r commented 1 year ago

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.