vue-apollo

问题描述

我正在尝试将一个 int 值作为秒标量传递给我的 graphql 后端。 前端使用 vue-apollo,后端使用 graphql-dotnet 在 dotnet core 中编写。

当我通过操场调用突变时,一切正常。我的 vue 应用程序既不会抛出任何错误/异常,也不会进行突变。更改在后端调用,但 s 的值为 null(因此 00:00:00,因为它是时间跨度)。后端是用 dotnet core 3.1 编写的,但正如我所说,从给定数字到 TimeSpanSecondsGraphType 的转换是通过操场进行的。

前端代码

我的突变看起来像

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

我的输入类型 s 看起来像

type s {
  s: Seconds = null
}

我的 SType 看起来像

type SType {
  s: Seconds
}

工作示例调用(通过操场)

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

这是我在 vue-app 中调用突变时来自 chrome 的负载(不工作):

{"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"}

编辑 - 添加后端代码

dotnet 核心突变和模型

这是我在后端的突变:

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);
                });

我的SInputType

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

还有我的S.cs

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

有什么建议吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)