Apollo / GraphQL:用于时间戳的字段类型?

时间:2016-12-11 19:28:53

标签: postgresql graphql apollostack

我正在将值存储到类型为timestamp with time zone的postgres字段中。我在我的Apollo架构中将该字段定义为int,但我在解析器中收到此错误消息:

column "apptDateTime" is of type timestamp with time zone but expression is of type integer

查找GraphQL data types,我还没有看到引用的任何类型对应于timestamp类型的字段。

对于数据库中类型为timestamp的字段,在Apollo模式中使用的正确字段类型是什么?

2 个答案:

答案 0 :(得分:0)

我的变异工作包括Timestamp和Time Zone类型的字段。我是通过将我的apptDateTime字段的模式从Int更改为String并传入ISO字符串来实现的。 Sequelize和Postgres负责将其更改为Time Zone与Time Zone类型的字段。

答案 1 :(得分:0)

我发现这种方式可以处理表单中的输入,需要从客户端(输入表单)转换为服务器,从服务器转换为客户端(输入表单)

Graphql:

    updatedAt: String

Sequelize:

    updatedAt: {  type: Sequelize.DATE },

PostgreSQL的:

    "createdAt" timestamp(6) with time zone DEFAULT now(),

值转换为服务器:

  value  = dateToISO(value);

将值转换为客户端:

  if ( isNil(value) ) {
    value = '';
  } else {
    value  =  value.toLocaleDateString() +' '+ value.toLocaleTimeString();
  }
帮助者:

let dateToISO = function (dateString) {
  if (!dateString) {
    return null;
  }
  let p = dateString.split(/\D/g);
  /* It's up your date on input in this case come from DD-MM-YYYY
    for MM-DD-YYY use: return [p[1], p[2], p[0]].join('-'); */
  return [p[2], p[1], p[0]].join('-'); 

};
相关问题