0

I'm trying to pass an int value as seconds scalar to my graphql-backend. The frontend uses vue-apollo and the backend is written in dotnet core using graphql-dotnet.

When I call the mutation via playground, everything works fine. Neither does my vue app throw any error/exception nor works the mutation. The mutation is called in the backend, but the value for s is null (and so 00:00:00 as it is a TimeSpan). The backend is written in dotnet core 3.1 but as I said the convertion from a given number to TimeSpanSecondsGraphType works via playground.

frontend code

My mutation looks like

updateS(
  sId: ID = null
  s: s = null
): SType

My input type s looks like

type s {
  s: Seconds = null
}

And my SType looks like

type SType {
  s: Seconds
}

Working example call (via playground)

mutation {
  updateS(s: "08d924e8-69fb-425c-8130-de7342a2ca2a", s: {
    s: 3600
  }) {
    s
  }
}

This is the payload from chrome when I call the mutation in my vue-app (not working):

{"operationName":"updateS","variables":{"sId":"08d924e8-69fb-425c-8130-de7342a2ca2a","s":{"s":3600}},"query":"mutation updateS($sId: ID!, $s: s!) {\n  updateS(sId: $sId, s: $s) {\n   s\n__typename\n  }\n}\n"}

Edit - Added backend code

dotnet core mutation and models

This is my mutation in the backend:

Field<SType>(
                "updateS",
                arguments: new QueryArguments(
                    new QueryArgument<IdGraphType> { Name = "sId" },
                    new QueryArgument<SInputType> { Name = "s" }
                ),
                resolve: context =>
                {
                    var sId = context.GetArgument<Guid>("sId");
                    var s = context.GetArgument<S>("s"); // s.S is always {00:00:00} when called from vue app. 
                    return repo.UpdateS(sId, s);
                });

My SInputType:

public class SInputType : InputObjectGraphType
    {
        public SInputType()
        {
            Name = "s";
            Field<TimeSpanSecondsGraphType>("s");
        }
    }

And my S.cs:

public class S
    {
        public Guid Id { get; set; }
        public TimeSpan S { get; set; }
    }

Any suggestion?

Andreas Sawatzki
  • 127
  • 2
  • 12
  • Did you tried in the graphql playground? – kissu Jun 14 '21 at 14:12
  • Yes, the working example works fine in playground. So I guess it's a bug in vue-apollo or a mistake i've made. – Andreas Sawatzki Jun 15 '21 at 07:34
  • Do you have the correct payload sent from the client? Check what is your payload in your chrome network tab. Also, what exactly is not working? – kissu Jun 15 '21 at 07:38
  • The payload is the last snippet in my question. That payload works also fine in playground. Whenever that query is called in my vue app the value for the Seconds scalar (in my case 3600) is not parsed to DateTimeSecondsGraphTyp and I get 0 as value. – Andreas Sawatzki Jun 15 '21 at 08:11
  • Uh sorry, what do you have as a response there so? Also, does it work with Insomnia or any other software that can send a GQL query? – kissu Jun 15 '21 at 08:12
  • I added the code for the backend to clarify the problem (see comment in the mutation). It works fine with Postman and Insomnia. – Andreas Sawatzki Jun 15 '21 at 08:52

0 Answers0