温馨提示:本文翻译自stackoverflow.com,查看原文请点击:node.js - GraphQL timestamp is different with database
graphql node.js postgresql

node.js - GraphQL时间戳与数据库不同

发布于 2020-03-31 23:05:05

为什么我在graphql中显示的时间戳与数据库不同?例如在我的数据库中显示2020-01-01 10:10:10。但是在graphql API中,我将2020-01-01T03:10:10.000Z。我正在使用postgresql作为数据库。这是我的代码:

const Notification =  new graphql.GraphQLObjectType({
  name: 'Notification',
  fields: () => ({
    id: { type: graphql.GraphQLInt },
    platform: { type: graphql.GraphQLString },
    action: { type: graphql.GraphQLString },
    image: { type: graphql.GraphQLString },
    title: { type: graphql.GraphQLString },
    highlight: { type: graphql.GraphQLString },
    bundle: { type: graphql.GraphQLString },
    sender: { type: graphql.GraphQLString },
    receiver: { type: graphql.GraphQLString },
    status: { type: graphql.GraphQLString },
    start_publish: {
      type: GraphQLDateTime
    },
    end_publish: { 
      type: GraphQLDateTime
      // resolve: (fields) => new Date(Date.UTC(fields.end_publish))
     },
    // team: {
    //   type: Team,
    //   sqlJoin: (playerTable, teamTable, args) => `${playerTable}.team_id = ${teamTable}.id` //innerjoin
    // }
  })
});

const QueryRoot = new graphql.GraphQLObjectType({
  name: 'Query',
  fields: () => ({
    notifications: {
      type: new graphql.GraphQLList(Notification),
      resolve: (parent, args, context, resolveInfo) => {
        return joinMonster.default(resolveInfo, {}, sql => {
          return client.query(sql)
        })
      }
    },
   //...
  })
})

查看更多

提问者
Yudha Pratama
被浏览
66
Yudha Pratama 2020-02-03 15:23

终于我设法从前端使用矩来设置它