Skip to content

Instantly share code, notes, and snippets.

@sejr
Created February 1, 2019 17:28
Show Gist options
  • Save sejr/3647b95e8f49355a8ae068c50d779379 to your computer and use it in GitHub Desktop.
Save sejr/3647b95e8f49355a8ae068c50d779379 to your computer and use it in GitHub Desktop.
Firegraph comparison
export async function getPosts(): Promise<PostListItem[]> {
const { posts } = await firegraph.resolve(firestore, gql`
query {
posts {
id
body
title
author(fromCollection: "users") {
id
displayName
photoURL
}
}
}
`);
return posts;
}
export async function getPosts(): Promise<PostListItem[]> {
const posts: any[] = [];
// Fetch from `posts` collection.
let postSnapshot = await firestore.collection('posts').get();
// For each post, we need to retrieve author info.
for (let post of postSnapshot.docs) {
const { id } = post;
const { title, body, author } = post.data();
const authorSnapshot = await firestore.doc(`users/${author}`).get();
const { displayName, photoURL } = authorSnapshot.data()!;
postAuthor = {
id: authorSnapshot.id,
displayName
photoURL
}
// Add the post to our list
posts.push({
id,
body,
title,
author: postAuthor
});
}
return posts as PostListItem[];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment