Warm tip: This article is reproduced from stackoverflow.com, please click
graphql node.js postgresql

GraphQL timestamp is different with database

发布于 2020-03-31 22:52:43

why my timestamp that show in graphql is different with the database? for example in my db its show 2020-01-01 10:10:10. But in graphql api i sh 2020-01-01T03:10:10.000Z. I'm using postgresql as my database. Here's my code :

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)
        })
      }
    },
   //...
  })
})
Questioner
Yudha Pratama
Viewed
62
Yudha Pratama 2020-02-03 15:23

finally i managed to set it from the front end using moment