Vue-Apollo中的GraphQL标量解析器

问题描述

我正在尝试在我的Vue-Apollo项目中为Date Scalar编写解析器。

在我的Apollo服务器中,我声明了scalar Date并为此类型创建了一个自定义解析器。 每次服务器发送Date对象时,适当的序列化函数都会自动将该类型转换为整数(符合JSON格式),反之亦然。

但是,在我的Vue.js客户端中,我找不到任何方法可以自动回退Vue中的自定义标量。 对于我进行的每个查询,我都需要手动将这些时间戳(int)转换为Date类型。

以下是服务器端的示例,摘自Apollo的官方网站:

const resolvers = {
  Date: new GraphQLScalarType({
    name: 'Date',description: 'Date custom scalar type',parseValue(value) {
      return new Date(value); // value from the client
    },serialize(value) {
      return value.getTime(); // value sent to the client
    },parseLiteral(ast) {
      if (ast.kind === Kind.INT) {
        return parseInt(ast.value,10); // ast value is always in string format
      }
      return null;
    },}),};

感谢您的时间(没有双关语)。

解决方法

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

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

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...