Skip to content

Commit 17de662

Browse files
committed
Add createdAt field
1 parent e6fe32d commit 17de662

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

functions/src/graphql/resolvers/Mutation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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")
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
export 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
};

functions/src/graphql/server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { resolvers } from "./resolvers";
33
import { firestore } from "./utils";
44

55
const 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 {

0 commit comments

Comments
 (0)