File tree Expand file tree Collapse file tree 3 files changed +8
-2
lines changed
Expand file tree Collapse file tree 3 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ export const Mutation = {
33 const { body } = args . input ;
44 return await firestore
55 . collection ( "messages" )
6- . add ( { body } )
6+ . add ( { body, createdAt : Date . now ( ) } )
77 . then ( async ref => {
88 const snapShot = await firestore
99 . collection ( "messages" )
Original file line number Diff line number Diff line change 11export const Query = {
22 messages : async ( parent , args , { firestore } ) => {
3- const snapShot = await firestore . collection ( "messages" ) . get ( ) ;
3+ const snapShot = await firestore
4+ . collection ( "messages" )
5+ . orderBy ( "createdAt" )
6+ . get ( ) ;
47 return snapShot . docs . map ( doc => ( { id : doc . id , ...doc . data ( ) } ) ) ;
58 }
69} ;
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { resolvers } from "./resolvers";
33import { firestore } from "./utils" ;
44
55const typeDefs = `
6+ scalar DateTime
7+
68 type Query {
79 hello(name: String): String!
810 messages: [Message!]!
@@ -15,6 +17,7 @@ const typeDefs = `
1517 type Message {
1618 id: String!
1719 body: String!
20+ createdAt: DateTime!
1821 }
1922
2023 input AddMessageInput {
You can’t perform that action at this time.
0 commit comments